| By Debu Panda | Article Rating: |
|
| June 26, 2007 09:15 AM EDT | Reads: |
25,083 |
Now let's explore how the Spring bean factory is created and how the Spring configuration is provided.
When an EJB instance is created (when a client invokes an EJB), the onEjbCreate method is invoked automatically. A JNDI lookup is done to obtain the path for the bean factory by using an environment entry named ejb/BeanFactoryPath. So you have to define it in the EJB deployment descriptor for the EJB:
<session>
<display-name>PlaceBid</display-name>
<ejb-name>PlaceBid</ejb-name>
<env-entry>
<env-entry-name>ejb/BeanFactoryPath</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>/actionBazaar-service.xml</env-entry-value>
</env-entry>
</session>
Although EJB 3 made deployment descriptor optional there are a few cases where you still have to use it. If you're a heavy Spring user you live and breath XML configurations so you have nothing to complain about! In our example we've set the env-entry-value for the ejb/BeanFactoryPath environment variable at /actionBazaar-service.xml. So you have to package the EJB classes, Spring classes, and Spring configuration file into your ejb-jar package.
This way you can use the declarative security, transaction, remoteability, and Web Service features of EJB and combine that with POJO injection, AOP, simplified data, and resource access of Spring. Next we'll see a powerful combination of MDB and Spring JmsTemplate.
JmsTemplate and Message-Driven Beans
Message-driven Beans are simple to develop and can be configured as a message consumer. MDBs support several performance features such as pooling and may either be used with a JMS-compliant provider or an EIS using a JCA 1.5-compliant connector. Below is a simple MDB configured against a JMS provider.
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName =
"destinationName", propertyValue =
"jms/OrderBillingQueue"),
@ActivationConfigProperty(propertyName =
"destinationType",propertyValue =
"javax.jms.Queue") })
public class OrderBillingMDB implements MessageListener {
public void onMessage(Message message) {
}
Building JMS producer with Java EE 5 is still a pretty complex task in spite of its injection support. Spring makes building a message producer application very simple as evident in the following code:
public void sendMessage() {
try {
..
JMSSender jmsSender =
(JMSSender)appContext.getBean("jmsSender");
jmsSender.sendMesage();
} catch(Exception e) {
e.printStackTrace();
}
}
Looks pretty simple! You must be wondering: what is the connection factory and destination configured that this client is sending a message to? The magic is done in background by the Spring configuration as specified below:
<bean id="connectionFactory">
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jms/QueueConnectionFactory</value>
</property>
</bean>
<bean id="jmsDestination"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jms/OrderBillingQueue</value>
</property>
</bean>
<bean id="jmsTemplate"
class="org.springframework.jms.core.JmsTemplate102">
<property name="connectionFactory">
<ref bean="connectionFactory"/>
</property>
<property name="defaultDestination">
<ref bean="jmsDestination"/>
</property>
</bean>
<bean id="jmsSender" class="oracle.fusion.demo.OrderService">
<property name="jmsTemplate">
<ref bean="jmsTemplate"/>
</property>
</bean>
If you look at this code, the JMS producer code is very simple, however, you have to write quite a bit of XML configuration. It's your choice!
Published June 26, 2007 Reads 25,083
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Debu Panda
Debu Panda, lead author of the recently published EJB 3 in Action (Manning Publications), is a senior principal product manager on the Oracle Application Server development team, where he drives development of the Java EE container. He has more than 15 years of experience in the IT industry and has published numerous articles on enterprise Java technologies and has presented at many conferences. Debu maintains an active blog on enterprise Java at http://www.debupanda.com.
![]() |
jcl 11/24/09 01:16:00 PM EST | |||
Hi,thank you for this tutorial I'm interested on the first way to intregate Spring and EJB3. I have tried it in a example project buy it doesn't run. I'm searching since many time a solution,but nothing. I have posted on Spring forum,but no one seems can help me. I appreciate if you can help me.Thank you Antonio |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?










































