O'Reilly logo

Java EE 7 Developer Handbook by Peter A. Pilgrim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JMS and dependency injection

JMS 2.0 is a major improvement because the specification leverages Java annotations. The standard also recognizes the advanced features of the Java EE 7 platform. In particular, JMS is designed to integrate with CDI, EJB, and other new endpoints.

Injecting CDI beans

JMS 2.0 supports context and dependency injection through injection of the JMSContext. We have already seen examples. It is also possible to inject the connection factory and then create a context.

Here is a code snippet that demonstrates this technique:

class XMLPublisher { @Resource(mappedName="xmlQueueConnectionFactory") ConnectionFactory queueConnectionFactory; @Resource(mappedName="xmlQueue") Queue queue; private static Logger logger = Logger.getLogger(XMLPublisher.class) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required