For development of Message Driven POJOs (see cute tutorial on Spring blogs) I need some testing environment with running JMS server. As I’m using Maven and his Jetty plugin, I found following solution.
Configuring Jetty
For configuring Jetty with JNDI, we need to place some configuration options into its configuration files. There are three options:
- jetty.xml
- WEB-INF/jetty-env.xml
- context xml file
For me, the most easiest way is to use the jetty-env.xml in WEB-INF directory. So I created this file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="wac">
<New id="connectionFactory">
<Arg>jms/connectionFactory</Arg>
<Arg>
<New>
<Arg>tcp://localhost:61616</Arg>
</New>
</Arg>
</New>
<New id="requestQueue">
<Arg>jms/requestQueue</Arg>
<Arg>
<New>
<Arg>requestQueue</Arg>
</New>
</Arg>
</New>
<New id="replyQueue">
<Arg>jms/replyQueue</Arg>
<Arg>
<New>
<Arg>replyQueue</Arg>
</New>
</Arg>
</New>
</Configure>
Next step is to setup resources in web.xml file to use this JNDI resources.
<resource-ref>
<description>Connection Factory</description>
<res-ref-name>jms/connectionFactory</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-env-ref>
<resource-env-ref-name>jms/requestQueue</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
<resource-env-ref>
<resource-env-ref-name>jms/replyQueue</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
Configuring Spring context.xml
The hardest stuff is behind us
Just now, we can use the jee schema for configuring beans.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
<jee:jndi-lookup id="connectionFactory" jndi-name="javax.jms.QueueConnectionFactory"></jee:jndi-lookup>
<jee:jndi-lookup id="replyQueue" jndi-name="Queue-0"></jee:jndi-lookup>
<jee:jndi-lookup id="requestQueue" jndi-name="Queue-1"></jee:jndi-lookup>
</beans>
Running
Don’t forget to start your ActiveMQ server and than just fire up maven jetty:run. But it will work better, if you use following snippet in your pom file
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>process-test-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>2.8</version>
</dependency>
</dependencies>
</plugin>
Configuring Jetty with ActiveMQ and JNDI
For development of Message Driven POJOs (see cute tutorial on Spring blogs) I need some testing environment with running JMS server. As I’m using Maven and his Jetty plugin, I found following solution.
Configuring Jetty
For configuring Jetty with JNDI, we need to place some configuration options into its configuration files. There are three options:
For me, the most easiest way is to use the jetty-env.xml in WEB-INF directory. So I created this file:
Next step is to setup resources in web.xml file to use this JNDI resources.
Configuring Spring context.xml
The hardest stuff is behind us
Just now, we can use the jee schema for configuring beans.
Running
Don’t forget to start your ActiveMQ server and than just fire up maven jetty:run. But it will work better, if you use following snippet in your pom file