Escolar Documentos
Profissional Documentos
Cultura Documentos
Now! (Java EE 5)
EJB
Hangover of EJB overdose over frameworks appeared to simplify complexities of enterprise Java!
Lightweight
Every
Slide 3
Slide 4
No need of home interface Annotations for type of EJB and interface Deployment descriptor is optional
Slide 5
Slide 6
EJB 3 Example
@Stateless public class PlaceBidBean implements PlaceBid { public Long addBid(Bid bid) { .. } }
Slide 7
Slide 8
Transaction management
Tightly integrated through JPA Robust support through Stateful Session Beans and Extended Persistence Context Seamless support for JAX-WS 2.0
Framework support for JPA, Hibernate, TopLink, JDBC, iBatis Indirect support dependent on web container session management
Web services
Poor direct support, best integration available is via configuring XFire for registered beans.
Messaging
Need to add configuration for each message listener. However, JMSTemplate and MessageListenerAdapter add nice abstraction. Remoting support may be added via configuration. Remote transactions and security are not supported. However protocols other than RMI such as Hessian and Burlap are supported. Robust support through AspectJ.
Remoting
Integrated support through Session Bean remote interfaces. Supports distributed transactions and security.
AOP
Security
Integrated support for declarative and programmatic security through JAAS. Simple scheduling possible through EJB Timer service.
Must add and configure Acegi security. However, support beyond JAAS is possible through Acegi. Must add and configure Quartz for scheduling.
Scheduling
Slide 10
Slide 11
Spring Configuration
<bean id="entityManager" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>java:comp/env/actionBazaar</value> </property> .. </bean> <bean id="bidService" class="actionbazaar.buslogic.BidServiceBean"> <property name="bidEAO"> <ref bean="bidEAO"/> </property> </bean> <bean id="bidEAO" class="actionbazaar.persistence.eao.BidSpringEAO" autowire="byType"> <property name="entityManager" ref="entityManager"/> </bean>
Slide 12
EJB 3 Transactions
Natively integrated with JTA Transaction Manager Bean or Container managed
@Stateless @TransactionManagement(TransactionManagementType.CONTAINER ) public class PlaceBidBean implements PlaceBid { .. @TransactionAttribute(TransactionAttributeType.REQUIRED) public void addBid(Bid bid) { entityManager.persist(bid); } }
Slide 13
Slide 14
Slide 15
Slide 16
Slide 17
Slide 18
Slide 19
Slide 20
Slide 21
AOP in Spring
@Aspect public class AuditAspect { @Before("execution(public * *(..)) && @annotation(Auditable)") public void audit(JoinPoint joinPoint) { System.out.println("Entering: " + joinPoint); System.out.println(" with args: " + joinPoint.getArgs()); } } public class PlaceBidBean implements PlaceBid { .. @Auditable public void addBid(Bid bid) { sessionFactory.getCurrentSession().save(bid); } }
Slide 22
Slide 23
Transaction management
Tightly integrated through JPA Robust support through Stateful Session Beans and Extended Persistence Context Seamless support for JAX-WS 2.0
Framework support for JPA, Hibernate, TopLink, JDBC, iBatis Indirect support dependent on web container session management
Web services
Poor direct support, best integration available is via configuring XFire for registered beans.
Messaging
Need to add configuration for each message listener. However, JMSTemplate and MessageListenerAdapter add nice abstraction. Remoting support may be added via configuration. Remote transactions and security are not supported. However protocols other than RMI such as Hessian and Burlap are supported. Robust support through AspectJ.
Remoting
Integrated support through Session Bean remote interfaces. Supports distributed transactions and security.
AOP
Security
Integrated support for declarative and programmatic security through JAAS. Simple scheduling possible through EJB Timer service.
Must add and configure Acegi security. However, support beyond JAAS is possible through Acegi. Must add and configure Quartz for scheduling.
Scheduling
EJB 3 is the true pathright!? My boss wants me to use Spring. Is there a peaceful co-existence?
Slide 26
Slide 27
Slide 28
Slide 29
Slide 30
Summary
Both EJB 3 and Spring can be used complimentary technology together
Slide 32
Resources
Spring and Java EE : Simplicity and Power Combined (JDJ articles http://java.sys-con.com/read/393298.htm and http://java.sys-con.com/read/366297.htm ) Spring Framework (http://springframework.org/) OTN Spring Resource Center: http://otn.oracle.com/spring/ EJB 3 In Action (http://manning.com/panda) Spring in Action
Slide 33
http://manning.com/panda http://debupanda.com
Slide 34