From the Spring Framework to Java EE 7 Ivar Grimstad JDD 2013 @ivar_grimstad About the Speaker Ivar Grimstad Software Architect at Cybercom Sweden JDD 2013 @ivar_grimstad What this presentation is NOT about “ […] is so much better than […]!” JDD 2013 @ivar_grimstad What this presentation is NOT about “[…] rocks and […] sucks!” JDD 2013 @ivar_grimstad What this presentation IS about • Feature comparison • Migration from Spring Framework to Java EE JDD 2013 @ivar_grimstad Content • Background • Comparison of Spring Framework and Java EE • Convert Demo application to Java EE – Highlight differences and similarities • Lessons learned JDD 2013 @ivar_grimstad History 1998 • JPE JDD 2013 1999 • J2EE 1.2 2001 • J2EE 1.3 2002 • Spring 2003 • J2EE 1.4 2004 • Spring 1 2006 2009 2013 • Java EE 5 • Spring 2 • Java EE 6 • Spring 3 • Java EE 7 • Spring 4 @ivar_grimstad Spring Framework • Flexible • Lightweight • Modular • Extensible JDD 2013 @ivar_grimstad Java EE 7 JDD 2013 @ivar_grimstad Comparison of Selected Features Feature Spring 3.2.x Java EE 7 Dependency Injection Spring IoC CDI Web Framework Spring MVC JSF REST Spring MVC JAX-RS Transactions Annotations, AOP EJB, JTA Persistence JDBC Templates, Spring Data JPA Batch Spring Batch Batch Applications for Java Platform 1.0 WebSockets - Java API for WebSockets 1.0 Validation Spring Validation API Bean Validation API Security Spring Security Java EE Security Messaging JMS JMS JDD 2013 @ivar_grimstad Comparison of Selected Features Feature Spring 3.2.x Java EE 7 Dependency Injection Spring IoC CDI Web Framework Spring MVC JSF REST Spring MVC JAX-RS Transactions Annotations, AOP EJB, JTA Persistence JDBC Templates, Spring Data JPA Batch Spring Batch Batch Applications for Java Platform 1.0 WebSockets - Java API for WebSockets 1.0 Validation Spring Validation API Bean Validation API Security Spring Security Java EE Security Messaging JMS JMS JDD 2013 @ivar_grimstad Demo JDD 2013 @ivar_grimstad Demo Application • Online Cook Book – Web UI – REST API JDD 2013 @ivar_grimstad Demo Application Data Model JDD 2013 @ivar_grimstad Demo Application Architecture JDD 2013 @ivar_grimstad Spring Implementation JDD 2013 @ivar_grimstad Demo Application Characteristics • WEB Application • Based on Spring Framework • Mix of XML and Annotations JDD 2013 @ivar_grimstad Migration Steps 1. Add Java EE dependency 2. Layer for layer 1. Add layer specific Java EE configuration (web.xml, persistense.xml, faces-config.xml) 2. Add Java EE annotations 3. Replace Spring specific implementation with Java EE 4. Replace Spring injections with CDI 3. Remove Spring configuration 4. Remove Spring Dependencies JDD 2013 @ivar_grimstad Layer for Layer Walkthrough JDD 2013 @ivar_grimstad Preparations JDD 2013 @ivar_grimstad Dependency Injection Spring IoC @Autowired XML JDD 2013 CDI @Inject @ivar_grimstad Persistence Layer JDD 2013 @ivar_grimstad Persistence Layer Spring JDBC @Repository JdbcTemplate JDD 2013 JPA @PersistenceContext @Entity @OneToMany, @ManyToOne, @ManyToMany persistence.xml @ivar_grimstad Spring JDBC JDD 2013 @ivar_grimstad JPA JDD 2013 @ivar_grimstad Service Layer JDD 2013 @ivar_grimstad Service Layer Spring POJO @Service @Transactional JDD 2013 EJB @Local @Stateless @ivar_grimstad Spring JDD 2013 @ivar_grimstad EJB JDD 2013 @ivar_grimstad REST API JDD 2013 @ivar_grimstad REST API Spring MVC @Controller @RequestMapping @ResponseBody @RequestBody @PathVariable @RequestParam JDD 2013 JAX-RS @Path @GET, @POST, @PUT, @DELETE @Consumes, @Produces @PathParam @QueryParam @ivar_grimstad Spring MVC JDD 2013 @ivar_grimstad JAX-RS JDD 2013 @ivar_grimstad Web UI JDD 2013 @ivar_grimstad Web UI JDD 2013 Spring MVC JSP Java ServerFaces XHTML @Controller @RequestMapping @Named @ivar_grimstad Spring MVC Controller JDD 2013 @ivar_grimstad JSF Controller JDD 2013 @ivar_grimstad Spring resources (i18n) applicatonContext.xml Create.jsp JDD 2013 @ivar_grimstad JSF resources (i18n) faces-config.xml Create.xhtml JDD 2013 @ivar_grimstad Remove Spring JDD 2013 @ivar_grimstad Application Architecture - Spring JDD 2013 @ivar_grimstad Application Architecture – Java EE JDD 2013 @ivar_grimstad Migration Steps – what we did 1. Added Java EE dependency 2. Layer for layer 1. Added layer specific Java EE configuration (web.xml, persistense.xml, faces-config.xml) 2. Added Java EE annotations 3. Replaced Spring specific implementation with Java EE 4. Replaced Spring injections with CDI 3. Removed Spring configuration 4. Removed Spring Dependencies JDD 2013 @ivar_grimstad Dependencies (Spring) JDD 2013 @ivar_grimstad Dependencies (Java EE) JDD 2013 @ivar_grimstad WAR File (Spring) JDD 2013 @ivar_grimstad WAR File (Java EE) JDD 2013 @ivar_grimstad What about testing? • Spring Framework has excellent support for testing • No direct support for testing in Java EE 7 • Tools like Arquillian is an option JDD 2013 @ivar_grimstad Not Covered Here • Simplified JMS • Java API for WebSocket 1.0 • JSON Processing 1.0 • Batch Applications for Java Platform 1.0 JDD 2013 @ivar_grimstad Why Migrate? • Spring IS a proprietary framework • Java EE is a standard • Many Spring applications run in a Java EE container anyway JDD 2013 @ivar_grimstad When NOT to Migrate? • If your target platform is prior to Java EE 6 • If your developers are experts on Spring Framework • If your application is heavily based on AOP JDD 2013 @ivar_grimstad Lessons Learned • Migration is not that hard • How hard it is depends on application structure • Migration from newer Spring version is easier – may even be required to upgrade first • Not all applications can be migrated JDD 2013 @ivar_grimstad Wrap Up JDD 2013 @ivar_grimstad JDD 2013 @ivar_grimstad