SlideShare a Scribd company logo
1 of 50
Download to read offline
Java EE vs. Spring
Smackdown
Mert Çalışkan, @mertcal
MuratYener, @yenerm
• MuratYener
• 10+Years of Java & Mobile
• Coder @ intel.com
• Google Developer Expert (Android)
• Profile available @ 

tr.linkedin.com/in/muratyener
• @yenerm
The Fighters
• Mert Çalışkan
• 10+Years of Enterprise Java
• Coder @ t2.com.tr
• Oracle Java Champion
• Profile available @

tr.linkedin.com/in/mertcaliskan
• @mertcal
• MuratYener
• 10+Years of Java & Mobile
• Coder @ intel.com
• Google Developer Expert (Android)
• Profile available @ 

tr.linkedin.com/in/muratyener
• @yenerm
The Fighters
• Mert Çalışkan
• 10+Years of Enterprise Java
• Coder @ t2.com.tr
• Oracle Java Champion
• Profile available @

tr.linkedin.com/in/mertcaliskan
• @mertcal
The Books that started it all…
http://amazon.com/author/murat http://amazon.com/author/mert
or DOYOU NEED SPECIAL
ABILITIES?
IS JAVA EE ENOUGH?
Come to the Spring Side..!
Current Trend on Java EE and Spring Framework
http://www.google.com/trends/explore#q=Java%20EE%2C%20Spring%20Framework
in 2 versions, one with Java EE 7 and one with Spring 4!
So we created a Sample Application named
No project, server, framework or even a POJO has been harmed
during the preparation on this talk.
Still we’re professionals so don’t try this at home (but you may
do try at work…)
Disclaimer
This talk is fiction, we are not messengers of either platform. We
both used each framework in a project at some point in our lifes
and we reserve to switch sides at any time in future.
Still for the sake of our book sells, we encourage you to pick the
best side and stick with it forever!
Disclaimer II
•Persistence
•CRUD
•Services
•REST
•Patterns
Simple Domain
Fighter
Schedule
ScoreBoard
Game
schedules
has
has
What is Fight Club?
J2EE
• Complete redesign of Enterprise Java
• Based on Spring
• Java EE and the Ewoks
Java EE
Spring
• Started with aim for simplifying J2EE
• Based on POJO programming model
• Offered DI instead of JNDI
• Enabled use of lightweight web servers instead of heavy J2EE server
JavaEE7 Spring
CDI Spring IoC
Interceptor Spring AOP AspectJ
JPA Persistence
Dependency Injection
AOP
JPA JDBC
UIJSF 2 Spring MVC JSF 2
WSJAX-WSJAX-RS
Spring MVC
REST Support
Security Spring Security
Contract-first
SOAP WS
TestingN/A Spring Testing
Java EE
Security
EJB
<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-webmvc</artifactId>

<version>4.1.5.RELEASE</version>

</dependency>



<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-orm</artifactId>

<version>4.1.5.RELEASE</version>

</dependency>
<dependency>

<groupId>javax</groupId>

<artifactId>javaee-web-api</artifactId>

<version>7.0</version>

<scope>provided</scope>

</dependency>
}
expressionbeanscontext coreweb
Maven as Dependency Manager
JavaEE7
Spring
webmvc
aop
}
Setup
IDE: NetBeans 8.0.2 Intellij IDEA 14 Ultimate
Server: Payara Payara
On IDEA, Mert needed to register

glassfish-resources.xml file with command: 

./asadmin add-resources ~/path-to-file/glassfish-resources.xml

and then start derby DB with 

./asadmin start-database

and then connect to the sample Db with ij.sh as:

ij> connect 'jdbc:derby://localhost:1527/sample;create=true’
SpringJavaEE
‘0’

config
Configuration
• Context configuration file (either as an
XML file or a Java class) is needed to
bootstrap the application.
• With Spring MVC, the location of the
configuration file is provided to the
Dispatcher Servlet definition in
web.xml.
• It’s also possible to provide multiple
configuration files and they will be
merged prior to context initialization.
SpringJavaEE
Java EE: bootstrapping
<beans/>

An empty beans.xml was needed to start the CDI container..
not any more
Spring: bootstrapping - 1
<?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:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:task="http://www.springframework.org/schema/task"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop.xsd

http://www.springframework.org/schema/task

http://www.springframework.org/schema/task/spring-task.xsd">



<context:component-scan base-package="com.devchronicles"/>

<context:annotation-config/>

<mvc:annotation-driven/>

<tx:annotation-driven/>

<task:annotation-driven/>

<tx:jta-transaction-manager/>

<aop:aspectj-autoproxy/>
Spring: bootstrapping - 2 - con’td
<bean id="viewResolver"

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/WEB-INF/pages/"/>

<property name="suffix" value=".jsp"/>

</bean>

<bean id="entityManagerFactory"

class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

<property name="dataSource" ref="dataSource"/>

<property name="persistenceUnitName" value="fightclub-jpa"/>

<property name="jpaVendorAdapter">

<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">

<property name="showSql" value="true"/>

</bean>

</property>

</bean>



<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

<property name="jndiName" value="fightclub"/>

</bean>

</beans>
More configuration to come for security & testing…
JavaEE's web.xml
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/
javaee/web-app_3_1.xsd"

version="3.1">



<servlet>

<servlet-name>facesServlet</servlet-name>

<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>



<servlet-mapping>

<servlet-name>facesServlet</servlet-name>

<url-pattern>*.jsf</url-pattern>

</servlet-mapping>



</web-app>

Spring’s web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee

http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

version="3.1">



<display-name>FightClub Code Demonstration</display-name>



<servlet>

<servlet-name>springmvc</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath*:/applicationContext.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>



<servlet-mapping>

<servlet-name>springmvc</servlet-name>

<url-pattern>/app/*</url-pattern>

</servlet-mapping>

</web-app>

Bean Declaration
JavaEE7 Spring
@Stateless

@Path("fighter")

public class FighterService {



@PersistenceContext

private EntityManager entityManager;



@Inject 

Event<Fighter> event;



@POST

@Consumes({"application/xml",
"application/json"})

public void create(Fighter fighter) {

entityManager.persist(fighter);

event.fire(fighter);

}

}
@RestController

@RequestMapping(value = "/fighters")

public class FighterRestController {



@PersistenceContext

private EntityManager entityManager;



@RequestMapping(value = "/create", method =
RequestMethod.POST)

public void create(@RequestBody Fighter fighter) {

entityManager.persist(fighter);

}

}
• @Named

derivatives: @Stateless, @Stateful
• @Inject, @EJB, @Resource
• @Alternative
• @PostConstruct, @PreDestroy
• @Dependent

@Request

@ConversationScoped

@SessionScoped

@ApplicationScoped
• @Produces
Annotations
• @Component

derivatives: @Service, @Controller, @Repository
• @Autowired
• @Primary
• @PostConstruct, @PreDestroy
• @Scope(BeanDefinition.SCOPE_PROTOTYPE) 

@Scope(“request”)

N/A (w/ Spring WebFlow)

@Scope(“session”)

@Scope(BeanDefinition.SCOPE_SINGLETON)
• @Configuration + @Bean
SpringJavaEE7
Design Patterns
@Singleton
@Observes
@Produces
@Decorator + XML (for order)
@Interceptor
@Inject++
@Asynchronous, Servlet 3.0+,
Websockets
@Schedule
@Component and its derivatives
N/A, github: spring-event-annotations
@Configuration + @Bean
N/A, github: spring-decorator
@Aspect, @Around, @After, @AfterReturning,
@AfterThrowing, @Before, @Pointcut
@Autowired
@Async
@Scheduled
Singleton
Observer
Factory
Decorator
AOP
Dependency
Injection
Asynchronous
Programming
Timer
SpringJavaEE7
some code
UI
• JSF
• Component Based Framework
• Using CDI beans as backing beans

• FacesServlet configuration
• Others…
Angular + REST
GWT/Vaadin + CDI
• Spring MVC
• Action Based Framework
• Controllers and REST services to feed JSP
files and jQuery could be used (heavily…)
• DispatcherServlet configuraion
• Others…
Angular + REST
JSF, Vaadin, GWT
SpringJavaEE7
Java EE - JSF for UI / fighters.xml - 1
<h:form prependId="false">

<h:panelGrid id="fighterPanel" columns="2">

<h:outputText value="Name"/>

<h:inputText id="txt_name" value="#{fighterBean.newFighter.name}"/>

<h:outputText value="Lastname"/>

<h:inputText id="txt_lastName" value="#{fighterBean.newFighter.lastname}"/>

<h:outputText value="Nickname"/>

<h:inputText id="txt_nickname" value="#{fighterBean.newFighter.nickname}"/>

<h:outputText value="Birth Date (dd-MM-yyyy)"/>

<h:inputText id="txt_birthdate" value="#{fighterBean.newFighter.birthDate}">

<f:convertDateTime pattern="dd-MM-yyyy"/>

</h:inputText>

</h:panelGrid>

<h:commandButton id="btn_save" value="Add" action="#{fighterBean.addFighter}">

<f:ajax render="fighters" />

</h:commandButton>

</h:form>
Java EE - JSF for UI / fighters.xml - 2 cont’d
<h:dataTable id="fighters"
value="#{fighterBean.fighters}" var="f"
border="1">

<h:column>

<f:facet name="header">

<h:outputText value="Name"/>

</f:facet>

<h:outputText value="#{f.name}"/>

</h:column>

<h:column>

<f:facet name="header">

<h:outputText value="Last Name"/>

</f:facet>

<h:outputText value="#{f.lastname}"/>

</h:column>

<h:column>

<f:facet name="header">

<h:outputText value="Nickname"/>

</f:facet>

<h:outputText value="#{f.nickname}"/>

</h:column>
<h:column>

<f:facet name="header">

<h:outputText value="Birth Date"/>

</f:facet>

<h:outputText value="#{f.birthDate}">

<f:convertDateTime pattern="dd-MM-yyyy"/>

</h:outputText>

</h:column>

<h:column>

<f:facet name="header">

</f:facet>

<h:commandLink
action="#{fighterBean.updateFighter(f)}">

<f:ajax render="fighterPanel fighters" />

<h:outputText value="Update" />

</h:commandLink>

</h:column>

<h:column>

<f:facet name="header">

</f:facet>

<h:commandLink
action="#{fighterBean.removeFighter(f)}">

<f:ajax render="fighterPanel fighters" />

<h:outputText value="Delete" />

</h:commandLink>

</h:column>

</h:dataTable>
Spring MVC for UI - 1
<mvc:form modelAttribute="fighter" action="saveFighter">

<table>

<tr>

<td><mvc:label path="name">Name</mvc:label></td>

<td><mvc:input path="name" /></td>

</tr>

<tr>

<td><mvc:label path="lastname">Last Name</mvc:label></td>

<td><mvc:input path="lastname" /></td>

</tr>

<tr>

<td><mvc:label path="nickname">Nick Name</mvc:label></td>

<td><mvc:input path="nickname" /></td>

</tr>

<tr>

<td><mvc:label path="birthDate">Birth Date (dd/MM/yyyy)</mvc:label></td>

<td><mvc:input path="birthDate" /></td>

</tr>

<tr>

<td colspan="2">

<input type="submit" value="Submit" />

</td>

</tr>

</table>
Spring MVC for UI - 2 cont’d
<table style="width: 800px;" border="1">

<tr>

<th>Name</th>

<th>Last Name</th>

<th>Nick Name</th>

<th>Birth Date</th>

<th/> 

<th/>

</tr>

<c:forEach var="f" items="${fighters}">

<tr>

<td>${f.name}</td>

<td>${f.lastname}</td>

<td>${f.nickname}</td>

<td>${f.birthDate}</td>

<td><a href="<c:url value='editFighter/${f.id}' />">Edit</a></td>

<td><a href="<c:url value='removeFighter/${f.id}' />">Delete</a></td>

</tr>

</c:forEach>

</table>

</mvc:form>
some more code
@Transactional
• @Transactional under package

javax.transaction
• With Java EE7 enables transactions in
CDI methods as well as EJB methods.
• isolation levels supported: REQUIRED,
REQUIRES_NEW, MANDATORY,
SUPPORTS, NOT_SUPPORTED, NEVER
• EJB3 impl come with JTA configured by
default.
• No readOnly transaction support
• @Transactional under package
org.springframework.transaction.annotat
ion
• Spring handled transactions with this
annotation since v1.2
• Isolation levels supported: Java EE ones
+ NESTED.
• Transaction manager should be
configured in order to handle JTA
@Transactional(readOnly = true)
SpringJavaEE7
AOP and Caching
• ServletFilter

• @WebFilter (Servlet 3.0)



• @Interceptor, @AroundInvoke



• @PostConstruct, @PreDestroy
• Spring provides AOP with proxy
pattern at runtime.
• It employs AspectJ annotations for
configuration (but not doing compile
time weaving…only runtime)
• Spring Caching offers an abstraction on
3rd party cache providers like Ehcache,
Hazelcast, Guava and etc.
• Complies with Pointcut designators
like, within(), execution(), bean(),
@annotation() and others.
SpringJavaEE7
JavaEE - Method Execution Time Logging
@Interceptor
public class LogInterceptor {    
    @AroundInvoke
    public Object doSecurityCheck(InvocationContext context) throws Exception{
long startTime = System.nanoTime();



String className =context.getMethod().getDeclaringClass().getCanonicalName();

String methodName = context.getMethod().getName();
Object execution= context.proceed()


long elapsedTime = System.nanoTime() - startTime;

Logger.getLogger("LOG").info("Execution of " + className + "#" + methodName +
" ended in " + new BigDecimal(elapsedTime).divide(new BigDecimal(1000000)) + " milliseconds");



return execution;
   }
@PostConstruct
public void onStart(){
Logger.getLogger("SecurityLog").info(“Activating");
}
@PreDestroy
public void onShutdown(){
Logger.getLogger("SecurityLog").info(“Deactivating");
}
}
Spring - Method Execution Time Logging
@Component

@Aspect

public class ExecutionTimeLogging {



@Around("within(com.devchronicles..*)")

public Object profile(ProceedingJoinPoint pjp) throws Throwable {

long startTime = System.nanoTime();



String className = pjp.getTarget().getClass().getCanonicalName();

String methodName = pjp.getSignature().getName();



Object output = pjp.proceed();


long elapsedTime = System.nanoTime() - startTime;

System.out.println("Execution of " + className + "#" + methodName +
" ended in " + new BigDecimal(elapsedTime).divide(new BigDecimal(1000000)) + " milliseconds");



return output;

}

}
Security
• Declarative: (basic, form based, digest, client,
mutual)
• via resources: resource/pattern/role
• via annotations: @HttpMethodConstraint,
@HttpConstraint, @ServletSecurity
• Programmatic: request.login(userName,
password);
• Message Security: via header in SOAP
messages
• JAAS & web.xml security
• Alternatively..Apache Shiro
• Provides w/ subproject Spring Security
• Supports several different authentication
methods

login form–based authentication, authentication with X509 user
certificates, LDAP authentication,Windows authentication over
legacy NTLM or Kerberos methods, 

basic and digest authentications.
• Separation of auth. methods from user
repositories i.e.: form-based auth from active
directory or a DB.
• Supports SSO w/ CAS, OpenID, SiteMinder,
and OAuth
• Guest login & built-in remember-me support
• HTTP/HTTPS support
JavaEE7 Spring
Java EE: Basic Authentication with Annotations
@WebServlet(name = "GreetingServlet", urlPatterns = {"/greeting"})
@ServletSecurity(
@HttpConstraint(transportGuarantee = TransportGuarantee.CONFIDENTIAL,
rolesAllowed = {"TutorialUser"}))
Java EE: Form based Authentication with XML
<security-constraint>
<display-name>Constraint1</display-name>
<web-resource-collection>
<web-resource-name>wrcoll</web-resource-name>
<description/>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>TutorialUser</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>file</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/error.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description/>
<role-name>TutorialUser</role-name>
</security-role>
Spring Security Dependencies
<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-web</artifactId>

<version>3.2.6.RELEASE</version>

</dependency>
for using Security namespaces.
for securing applications that depends 

on web services
<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-config</artifactId>

<version>3.2.6.RELEASE</version>

</dependency>
• Current latest version of Spring Security is 3.2.6.RELEASE and beware that it
ships with spring-core 3.2.8.RELEASE. So better to add 4.1.5.RELEASE
dependencies of spring-core manually.
Simplest Spring Security Configuration (Excerpt)


xsi:schemaLocation="http://www.springframework.org/schema/security 

http://www.springframework.org/schema/security/spring-security-3.2.xsd"



<security:user-service id="userService">

<security:user name="user1" password="secret" authorities="ROLE_USER"/>

</security:user-service>



<security:authentication-manager>

<security:authentication-provider user-service-ref="userService"/>

</security:authentication-manager>



<security:http pattern="/favicon.ico" security="none"/>

<security:http pattern="/app/rest/**" security="none"/>


<security:http auto-config="true">

<security:intercept-url pattern="/**" access="ROLE_USER"/>

</security:http>
web.xml for handling Spring Security
<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>



<filter>

<filter-name>springSecurityFilterChain</filter-name>

<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

</filter>

<filter-mapping>

<filter-name>springSecurityFilterChain</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>



<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath*:/applicationContext.xml</param-value>

</context-param>



<servlet>

<servlet-name>springmvc</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value></param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>
Testing
• JUnit
• OpenEJB Container (one line)
props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
• Embedded Glasfish Container
• Arquillian container tests
• JUnit + TestNG
• Offers integration testing support 

w/out the need of deploying app w/
Spring Testing.
• Offers Servlet API mock objects like
MockHttpServletRequest, MockHttpServletResponse,
MockHttpSession and others.
• Testing REST services is easy with the
builder API.
• Bean Profiling allows us to differentiate
DB connections for in DEV (derby) or
in TEST (hsqldb)
JavaEE7 Spring
Java EE - REST Service Testing
• JUnit
• Mockito
• Simple, just like Java SE
Spring Testing - Maven Dependencies
<spring.version>4.1.5.RELEASE</spring.version>
<hamcrest.version>1.3</hamcrest.version>
<junit.version>4.12</junit.version>

<hsqldb.version>2.3.2</hsqldb.version>


<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-test</artifactId>

<version>${spring.version}</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.hamcrest</groupId>

<artifactId>hamcrest-all</artifactId>

<version>${hamcrest.version}</version>

<scope>test</scope>

</dependency>
<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>${junit.version}</version>

<exclusions>

<exclusion>

<groupId>org.hamcrest</groupId>

<artifactId>hamcrest-core</artifactId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>org.hsqldb</groupId>

<artifactId>hsqldb</artifactId>

<version>${hsqldb.version}</version>

<scope>test</scope>

</dependency>
Spring - REST service testing
@RunWith(SpringJUnit4ClassRunner.class)

@WebAppConfiguration

@ContextConfiguration("classpath*:/applicationContext.xml")

public abstract class BaseControllerTests {

}
public class FighterRestControllerTests extends BaseControllerTests {



private MockMvc mockMvc;



@Autowired

private WebApplicationContext wac;



@Before

public void setup() {

this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();

}



@Test

public void getAllFightersMethodWorksOK() throws Exception {

mockMvc.perform(get("/fighters/all")) .andExpect(status().isOk())

.andExpect(content().contentType(MediaType.APPLICATION_JSON))

.andExpect(content().string(allOf(containsString("{"id":1,"name":"Mert","lastname":
"Caliskan","nickname":"mulderbaba","birthDate":"1980-12-14"}"))));

}

}

Books on Amazon stackoverflow
Release Timeline
10.2006
v2 v2.5
11.2007 12.2009 12.2011 12.2012 12.2013 09.2014 06.2015
v3 v3.1 v3.2 v4 v4.1 v4.2
Spring
Java EE
05.1998
JPE J2EE 1.2
12.1999 09.2001 11.2003 5.2006 12.2009 06.2013 Q3 2016
J2EE 1.3 J2EE 1.4 Java EE 5 Java EE 6 Java EE 7 Java EE 8
slowest iteration, biggest change!
FinalVerdict
•Spring is cool and so is Java EE.
•They are providing the best of breed (v4 & EE7) same motto,
different underlying infra.
•Java EE is standards designator, if you are starting a new
project, better to stick w/ the standards.
•If you are into sub-projects of Spring, like -data, -social, -batch,
and others like security, leverage the use of Spring.
•We are using both and we’re both happy :)
All sources are available under
•JavaEE7Version: 

https://github.com/yenerm/FightClub

•SpringVersion: 

https://github.com/mulderbaba/FightClub
Any questions
you have, hmm?
@yenerm
@mertcal

More Related Content

What's hot

Getting Reactive with Spring Framework 5.0’s GA release
Getting Reactive with Spring Framework 5.0’s GA releaseGetting Reactive with Spring Framework 5.0’s GA release
Getting Reactive with Spring Framework 5.0’s GA release
VMware Tanzu
 

What's hot (19)

Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
Java EE 8 Update
Java EE 8 UpdateJava EE 8 Update
Java EE 8 Update
 
Spring Mvc,Java, Spring
Spring Mvc,Java, SpringSpring Mvc,Java, Spring
Spring Mvc,Java, Spring
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
 
50 New Features of Java EE 7 in 50 minutes
50 New Features of Java EE 7 in 50 minutes50 New Features of Java EE 7 in 50 minutes
50 New Features of Java EE 7 in 50 minutes
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Spring Framework Rohit
Spring Framework RohitSpring Framework Rohit
Spring Framework Rohit
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
An Introduction to Play 2 Framework
An Introduction to Play 2 FrameworkAn Introduction to Play 2 Framework
An Introduction to Play 2 Framework
 
What's Coming in Java EE 8
What's Coming in Java EE 8What's Coming in Java EE 8
What's Coming in Java EE 8
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Java EE8 - by Kito Mann
Java EE8 - by Kito Mann Java EE8 - by Kito Mann
Java EE8 - by Kito Mann
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
 
Testdrive AngularJS with Spring 4
Testdrive AngularJS with Spring 4Testdrive AngularJS with Spring 4
Testdrive AngularJS with Spring 4
 
Getting Reactive with Spring Framework 5.0’s GA release
Getting Reactive with Spring Framework 5.0’s GA releaseGetting Reactive with Spring Framework 5.0’s GA release
Getting Reactive with Spring Framework 5.0’s GA release
 
Java spring framework
Java spring frameworkJava spring framework
Java spring framework
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
Testing Java EE Applications Using Arquillian
Testing Java EE Applications Using ArquillianTesting Java EE Applications Using Arquillian
Testing Java EE Applications Using Arquillian
 

Similar to jDays2015 - JavaEE vs. Spring Smackdown

Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
Andy Peterson
 

Similar to jDays2015 - JavaEE vs. Spring Smackdown (20)

สปริงเฟรมเวิร์ค4.1
สปริงเฟรมเวิร์ค4.1สปริงเฟรมเวิร์ค4.1
สปริงเฟรมเวิร์ค4.1
 
Karate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter ThomasKarate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter Thomas
 
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionJava EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
 
Java EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerJava EE 6 = Less Code + More Power
Java EE 6 = Less Code + More Power
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6
 
Spring and DWR
Spring and DWRSpring and DWR
Spring and DWR
 
Require js
Require jsRequire js
Require js
 
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
 
PrettyFaces URLRewrite for Servlet & JavaEE @ Devoxx 2010
PrettyFaces URLRewrite for Servlet & JavaEE @ Devoxx 2010PrettyFaces URLRewrite for Servlet & JavaEE @ Devoxx 2010
PrettyFaces URLRewrite for Servlet & JavaEE @ Devoxx 2010
 
Story ofcorespring infodeck
Story ofcorespring infodeckStory ofcorespring infodeck
Story ofcorespring infodeck
 
Spring.Boot up your development
Spring.Boot up your developmentSpring.Boot up your development
Spring.Boot up your development
 
Spring.new hope.1.3
Spring.new hope.1.3Spring.new hope.1.3
Spring.new hope.1.3
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdfdokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
 
DEVBCN_Jakarta EE! The future of enterprise application behind the myths. _Al...
DEVBCN_Jakarta EE! The future of enterprise application behind the myths.
_Al...DEVBCN_Jakarta EE! The future of enterprise application behind the myths.
_Al...
DEVBCN_Jakarta EE! The future of enterprise application behind the myths. _Al...
 
Java ee 7 New Features
Java ee 7   New FeaturesJava ee 7   New Features
Java ee 7 New Features
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 

More from Mert Çalışkan

Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack Implementation
Mert Çalışkan
 

More from Mert Çalışkan (6)

JavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesJavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
 
Better Career with Java
Better Career with JavaBetter Career with Java
Better Career with Java
 
Test Infected
Test InfectedTest Infected
Test Infected
 
Gelecex - Maven ile Akilli Projeler
Gelecex - Maven ile Akilli ProjelerGelecex - Maven ile Akilli Projeler
Gelecex - Maven ile Akilli Projeler
 
Fikrim Acik Kodum Acik
Fikrim Acik Kodum AcikFikrim Acik Kodum Acik
Fikrim Acik Kodum Acik
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack Implementation
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 

jDays2015 - JavaEE vs. Spring Smackdown

  • 1. Java EE vs. Spring Smackdown Mert Çalışkan, @mertcal MuratYener, @yenerm
  • 2. • MuratYener • 10+Years of Java & Mobile • Coder @ intel.com • Google Developer Expert (Android) • Profile available @ 
 tr.linkedin.com/in/muratyener • @yenerm The Fighters • Mert Çalışkan • 10+Years of Enterprise Java • Coder @ t2.com.tr • Oracle Java Champion • Profile available @
 tr.linkedin.com/in/mertcaliskan • @mertcal
  • 3. • MuratYener • 10+Years of Java & Mobile • Coder @ intel.com • Google Developer Expert (Android) • Profile available @ 
 tr.linkedin.com/in/muratyener • @yenerm The Fighters • Mert Çalışkan • 10+Years of Enterprise Java • Coder @ t2.com.tr • Oracle Java Champion • Profile available @
 tr.linkedin.com/in/mertcaliskan • @mertcal
  • 4. The Books that started it all… http://amazon.com/author/murat http://amazon.com/author/mert
  • 5. or DOYOU NEED SPECIAL ABILITIES? IS JAVA EE ENOUGH? Come to the Spring Side..!
  • 6. Current Trend on Java EE and Spring Framework http://www.google.com/trends/explore#q=Java%20EE%2C%20Spring%20Framework
  • 7. in 2 versions, one with Java EE 7 and one with Spring 4! So we created a Sample Application named
  • 8. No project, server, framework or even a POJO has been harmed during the preparation on this talk. Still we’re professionals so don’t try this at home (but you may do try at work…) Disclaimer
  • 9. This talk is fiction, we are not messengers of either platform. We both used each framework in a project at some point in our lifes and we reserve to switch sides at any time in future. Still for the sake of our book sells, we encourage you to pick the best side and stick with it forever! Disclaimer II
  • 11. J2EE • Complete redesign of Enterprise Java • Based on Spring • Java EE and the Ewoks Java EE
  • 12. Spring • Started with aim for simplifying J2EE • Based on POJO programming model • Offered DI instead of JNDI • Enabled use of lightweight web servers instead of heavy J2EE server
  • 13. JavaEE7 Spring CDI Spring IoC Interceptor Spring AOP AspectJ JPA Persistence Dependency Injection AOP JPA JDBC UIJSF 2 Spring MVC JSF 2 WSJAX-WSJAX-RS Spring MVC REST Support Security Spring Security Contract-first SOAP WS TestingN/A Spring Testing Java EE Security EJB
  • 15. Setup IDE: NetBeans 8.0.2 Intellij IDEA 14 Ultimate Server: Payara Payara On IDEA, Mert needed to register
 glassfish-resources.xml file with command: 
 ./asadmin add-resources ~/path-to-file/glassfish-resources.xml
 and then start derby DB with 
 ./asadmin start-database
 and then connect to the sample Db with ij.sh as:
 ij> connect 'jdbc:derby://localhost:1527/sample;create=true’ SpringJavaEE
  • 16. ‘0’
 config Configuration • Context configuration file (either as an XML file or a Java class) is needed to bootstrap the application. • With Spring MVC, the location of the configuration file is provided to the Dispatcher Servlet definition in web.xml. • It’s also possible to provide multiple configuration files and they will be merged prior to context initialization. SpringJavaEE
  • 17. Java EE: bootstrapping <beans/>
 An empty beans.xml was needed to start the CDI container.. not any more
  • 18. Spring: bootstrapping - 1 <?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:context="http://www.springframework.org/schema/context"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:mvc="http://www.springframework.org/schema/mvc"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:task="http://www.springframework.org/schema/task"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context.xsd
 http://www.springframework.org/schema/mvc
 http://www.springframework.org/schema/mvc/spring-mvc.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop.xsd
 http://www.springframework.org/schema/task
 http://www.springframework.org/schema/task/spring-task.xsd">
 
 <context:component-scan base-package="com.devchronicles"/>
 <context:annotation-config/>
 <mvc:annotation-driven/>
 <tx:annotation-driven/>
 <task:annotation-driven/>
 <tx:jta-transaction-manager/>
 <aop:aspectj-autoproxy/>
  • 19. Spring: bootstrapping - 2 - con’td <bean id="viewResolver"
 class="org.springframework.web.servlet.view.InternalResourceViewResolver">
 <property name="prefix" value="/WEB-INF/pages/"/>
 <property name="suffix" value=".jsp"/>
 </bean>
 <bean id="entityManagerFactory"
 class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
 <property name="dataSource" ref="dataSource"/>
 <property name="persistenceUnitName" value="fightclub-jpa"/>
 <property name="jpaVendorAdapter">
 <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
 <property name="showSql" value="true"/>
 </bean>
 </property>
 </bean>
 
 <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
 <property name="jndiName" value="fightclub"/>
 </bean>
 </beans> More configuration to come for security & testing…
  • 20. JavaEE's web.xml <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/ javaee/web-app_3_1.xsd"
 version="3.1">
 
 <servlet>
 <servlet-name>facesServlet</servlet-name>
 <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
 <load-on-startup>1</load-on-startup>
 </servlet>
 
 <servlet-mapping>
 <servlet-name>facesServlet</servlet-name>
 <url-pattern>*.jsf</url-pattern>
 </servlet-mapping>
 
 </web-app>

  • 21. Spring’s web.xml <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
 version="3.1">
 
 <display-name>FightClub Code Demonstration</display-name>
 
 <servlet>
 <servlet-name>springmvc</servlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 <init-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>classpath*:/applicationContext.xml</param-value>
 </init-param>
 <load-on-startup>1</load-on-startup>
 </servlet>
 
 <servlet-mapping>
 <servlet-name>springmvc</servlet-name>
 <url-pattern>/app/*</url-pattern>
 </servlet-mapping>
 </web-app>

  • 22. Bean Declaration JavaEE7 Spring @Stateless
 @Path("fighter")
 public class FighterService {
 
 @PersistenceContext
 private EntityManager entityManager;
 
 @Inject 
 Event<Fighter> event;
 
 @POST
 @Consumes({"application/xml", "application/json"})
 public void create(Fighter fighter) {
 entityManager.persist(fighter);
 event.fire(fighter);
 }
 } @RestController
 @RequestMapping(value = "/fighters")
 public class FighterRestController {
 
 @PersistenceContext
 private EntityManager entityManager;
 
 @RequestMapping(value = "/create", method = RequestMethod.POST)
 public void create(@RequestBody Fighter fighter) {
 entityManager.persist(fighter);
 }
 }
  • 23. • @Named
 derivatives: @Stateless, @Stateful • @Inject, @EJB, @Resource • @Alternative • @PostConstruct, @PreDestroy • @Dependent
 @Request
 @ConversationScoped
 @SessionScoped
 @ApplicationScoped • @Produces Annotations • @Component
 derivatives: @Service, @Controller, @Repository • @Autowired • @Primary • @PostConstruct, @PreDestroy • @Scope(BeanDefinition.SCOPE_PROTOTYPE) 
 @Scope(“request”)
 N/A (w/ Spring WebFlow)
 @Scope(“session”)
 @Scope(BeanDefinition.SCOPE_SINGLETON) • @Configuration + @Bean SpringJavaEE7
  • 24. Design Patterns @Singleton @Observes @Produces @Decorator + XML (for order) @Interceptor @Inject++ @Asynchronous, Servlet 3.0+, Websockets @Schedule @Component and its derivatives N/A, github: spring-event-annotations @Configuration + @Bean N/A, github: spring-decorator @Aspect, @Around, @After, @AfterReturning, @AfterThrowing, @Before, @Pointcut @Autowired @Async @Scheduled Singleton Observer Factory Decorator AOP Dependency Injection Asynchronous Programming Timer SpringJavaEE7
  • 26. UI • JSF • Component Based Framework • Using CDI beans as backing beans
 • FacesServlet configuration • Others… Angular + REST GWT/Vaadin + CDI • Spring MVC • Action Based Framework • Controllers and REST services to feed JSP files and jQuery could be used (heavily…) • DispatcherServlet configuraion • Others… Angular + REST JSF, Vaadin, GWT SpringJavaEE7
  • 27. Java EE - JSF for UI / fighters.xml - 1 <h:form prependId="false">
 <h:panelGrid id="fighterPanel" columns="2">
 <h:outputText value="Name"/>
 <h:inputText id="txt_name" value="#{fighterBean.newFighter.name}"/>
 <h:outputText value="Lastname"/>
 <h:inputText id="txt_lastName" value="#{fighterBean.newFighter.lastname}"/>
 <h:outputText value="Nickname"/>
 <h:inputText id="txt_nickname" value="#{fighterBean.newFighter.nickname}"/>
 <h:outputText value="Birth Date (dd-MM-yyyy)"/>
 <h:inputText id="txt_birthdate" value="#{fighterBean.newFighter.birthDate}">
 <f:convertDateTime pattern="dd-MM-yyyy"/>
 </h:inputText>
 </h:panelGrid>
 <h:commandButton id="btn_save" value="Add" action="#{fighterBean.addFighter}">
 <f:ajax render="fighters" />
 </h:commandButton>
 </h:form>
  • 28. Java EE - JSF for UI / fighters.xml - 2 cont’d <h:dataTable id="fighters" value="#{fighterBean.fighters}" var="f" border="1">
 <h:column>
 <f:facet name="header">
 <h:outputText value="Name"/>
 </f:facet>
 <h:outputText value="#{f.name}"/>
 </h:column>
 <h:column>
 <f:facet name="header">
 <h:outputText value="Last Name"/>
 </f:facet>
 <h:outputText value="#{f.lastname}"/>
 </h:column>
 <h:column>
 <f:facet name="header">
 <h:outputText value="Nickname"/>
 </f:facet>
 <h:outputText value="#{f.nickname}"/>
 </h:column> <h:column>
 <f:facet name="header">
 <h:outputText value="Birth Date"/>
 </f:facet>
 <h:outputText value="#{f.birthDate}">
 <f:convertDateTime pattern="dd-MM-yyyy"/>
 </h:outputText>
 </h:column>
 <h:column>
 <f:facet name="header">
 </f:facet>
 <h:commandLink action="#{fighterBean.updateFighter(f)}">
 <f:ajax render="fighterPanel fighters" />
 <h:outputText value="Update" />
 </h:commandLink>
 </h:column>
 <h:column>
 <f:facet name="header">
 </f:facet>
 <h:commandLink action="#{fighterBean.removeFighter(f)}">
 <f:ajax render="fighterPanel fighters" />
 <h:outputText value="Delete" />
 </h:commandLink>
 </h:column>
 </h:dataTable>
  • 29. Spring MVC for UI - 1 <mvc:form modelAttribute="fighter" action="saveFighter">
 <table>
 <tr>
 <td><mvc:label path="name">Name</mvc:label></td>
 <td><mvc:input path="name" /></td>
 </tr>
 <tr>
 <td><mvc:label path="lastname">Last Name</mvc:label></td>
 <td><mvc:input path="lastname" /></td>
 </tr>
 <tr>
 <td><mvc:label path="nickname">Nick Name</mvc:label></td>
 <td><mvc:input path="nickname" /></td>
 </tr>
 <tr>
 <td><mvc:label path="birthDate">Birth Date (dd/MM/yyyy)</mvc:label></td>
 <td><mvc:input path="birthDate" /></td>
 </tr>
 <tr>
 <td colspan="2">
 <input type="submit" value="Submit" />
 </td>
 </tr>
 </table>
  • 30. Spring MVC for UI - 2 cont’d <table style="width: 800px;" border="1">
 <tr>
 <th>Name</th>
 <th>Last Name</th>
 <th>Nick Name</th>
 <th>Birth Date</th>
 <th/> 
 <th/>
 </tr>
 <c:forEach var="f" items="${fighters}">
 <tr>
 <td>${f.name}</td>
 <td>${f.lastname}</td>
 <td>${f.nickname}</td>
 <td>${f.birthDate}</td>
 <td><a href="<c:url value='editFighter/${f.id}' />">Edit</a></td>
 <td><a href="<c:url value='removeFighter/${f.id}' />">Delete</a></td>
 </tr>
 </c:forEach>
 </table>
 </mvc:form>
  • 32. @Transactional • @Transactional under package
 javax.transaction • With Java EE7 enables transactions in CDI methods as well as EJB methods. • isolation levels supported: REQUIRED, REQUIRES_NEW, MANDATORY, SUPPORTS, NOT_SUPPORTED, NEVER • EJB3 impl come with JTA configured by default. • No readOnly transaction support • @Transactional under package org.springframework.transaction.annotat ion • Spring handled transactions with this annotation since v1.2 • Isolation levels supported: Java EE ones + NESTED. • Transaction manager should be configured in order to handle JTA @Transactional(readOnly = true) SpringJavaEE7
  • 33. AOP and Caching • ServletFilter
 • @WebFilter (Servlet 3.0)
 
 • @Interceptor, @AroundInvoke
 
 • @PostConstruct, @PreDestroy • Spring provides AOP with proxy pattern at runtime. • It employs AspectJ annotations for configuration (but not doing compile time weaving…only runtime) • Spring Caching offers an abstraction on 3rd party cache providers like Ehcache, Hazelcast, Guava and etc. • Complies with Pointcut designators like, within(), execution(), bean(), @annotation() and others. SpringJavaEE7
  • 34. JavaEE - Method Execution Time Logging @Interceptor public class LogInterceptor {         @AroundInvoke     public Object doSecurityCheck(InvocationContext context) throws Exception{ long startTime = System.nanoTime();
 
 String className =context.getMethod().getDeclaringClass().getCanonicalName();
 String methodName = context.getMethod().getName(); Object execution= context.proceed() 
 long elapsedTime = System.nanoTime() - startTime;
 Logger.getLogger("LOG").info("Execution of " + className + "#" + methodName + " ended in " + new BigDecimal(elapsedTime).divide(new BigDecimal(1000000)) + " milliseconds");
 
 return execution;    } @PostConstruct public void onStart(){ Logger.getLogger("SecurityLog").info(“Activating"); } @PreDestroy public void onShutdown(){ Logger.getLogger("SecurityLog").info(“Deactivating"); } }
  • 35. Spring - Method Execution Time Logging @Component
 @Aspect
 public class ExecutionTimeLogging {
 
 @Around("within(com.devchronicles..*)")
 public Object profile(ProceedingJoinPoint pjp) throws Throwable {
 long startTime = System.nanoTime();
 
 String className = pjp.getTarget().getClass().getCanonicalName();
 String methodName = pjp.getSignature().getName();
 
 Object output = pjp.proceed(); 
 long elapsedTime = System.nanoTime() - startTime;
 System.out.println("Execution of " + className + "#" + methodName + " ended in " + new BigDecimal(elapsedTime).divide(new BigDecimal(1000000)) + " milliseconds");
 
 return output;
 }
 }
  • 36. Security • Declarative: (basic, form based, digest, client, mutual) • via resources: resource/pattern/role • via annotations: @HttpMethodConstraint, @HttpConstraint, @ServletSecurity • Programmatic: request.login(userName, password); • Message Security: via header in SOAP messages • JAAS & web.xml security • Alternatively..Apache Shiro • Provides w/ subproject Spring Security • Supports several different authentication methods
 login form–based authentication, authentication with X509 user certificates, LDAP authentication,Windows authentication over legacy NTLM or Kerberos methods, 
 basic and digest authentications. • Separation of auth. methods from user repositories i.e.: form-based auth from active directory or a DB. • Supports SSO w/ CAS, OpenID, SiteMinder, and OAuth • Guest login & built-in remember-me support • HTTP/HTTPS support JavaEE7 Spring
  • 37. Java EE: Basic Authentication with Annotations @WebServlet(name = "GreetingServlet", urlPatterns = {"/greeting"}) @ServletSecurity( @HttpConstraint(transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = {"TutorialUser"}))
  • 38. Java EE: Form based Authentication with XML <security-constraint> <display-name>Constraint1</display-name> <web-resource-collection> <web-resource-name>wrcoll</web-resource-name> <description/> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <description/> <role-name>TutorialUser</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>FORM</auth-method> <realm-name>file</realm-name> <form-login-config> <form-login-page>/login.xhtml</form-login-page> <form-error-page>/error.xhtml</form-error-page> </form-login-config> </login-config> <security-role> <description/> <role-name>TutorialUser</role-name> </security-role>
  • 39. Spring Security Dependencies <dependency>
 <groupId>org.springframework.security</groupId>
 <artifactId>spring-security-web</artifactId>
 <version>3.2.6.RELEASE</version>
 </dependency> for using Security namespaces. for securing applications that depends 
 on web services <dependency>
 <groupId>org.springframework.security</groupId>
 <artifactId>spring-security-config</artifactId>
 <version>3.2.6.RELEASE</version>
 </dependency> • Current latest version of Spring Security is 3.2.6.RELEASE and beware that it ships with spring-core 3.2.8.RELEASE. So better to add 4.1.5.RELEASE dependencies of spring-core manually.
  • 40. Simplest Spring Security Configuration (Excerpt) 
 xsi:schemaLocation="http://www.springframework.org/schema/security 
 http://www.springframework.org/schema/security/spring-security-3.2.xsd"
 
 <security:user-service id="userService">
 <security:user name="user1" password="secret" authorities="ROLE_USER"/>
 </security:user-service>
 
 <security:authentication-manager>
 <security:authentication-provider user-service-ref="userService"/>
 </security:authentication-manager>
 
 <security:http pattern="/favicon.ico" security="none"/>
 <security:http pattern="/app/rest/**" security="none"/> 
 <security:http auto-config="true">
 <security:intercept-url pattern="/**" access="ROLE_USER"/>
 </security:http>
  • 41. web.xml for handling Spring Security <listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 
 <filter>
 <filter-name>springSecurityFilterChain</filter-name>
 <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
 </filter>
 <filter-mapping>
 <filter-name>springSecurityFilterChain</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
 
 <context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>classpath*:/applicationContext.xml</param-value>
 </context-param>
 
 <servlet>
 <servlet-name>springmvc</servlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 <init-param>
 <param-name>contextConfigLocation</param-name>
 <param-value></param-value>
 </init-param>
 <load-on-startup>1</load-on-startup>
 </servlet>
  • 42. Testing • JUnit • OpenEJB Container (one line) props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); • Embedded Glasfish Container • Arquillian container tests • JUnit + TestNG • Offers integration testing support 
 w/out the need of deploying app w/ Spring Testing. • Offers Servlet API mock objects like MockHttpServletRequest, MockHttpServletResponse, MockHttpSession and others. • Testing REST services is easy with the builder API. • Bean Profiling allows us to differentiate DB connections for in DEV (derby) or in TEST (hsqldb) JavaEE7 Spring
  • 43. Java EE - REST Service Testing • JUnit • Mockito • Simple, just like Java SE
  • 44. Spring Testing - Maven Dependencies <spring.version>4.1.5.RELEASE</spring.version> <hamcrest.version>1.3</hamcrest.version> <junit.version>4.12</junit.version>
 <hsqldb.version>2.3.2</hsqldb.version> 
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-test</artifactId>
 <version>${spring.version}</version>
 <scope>test</scope>
 </dependency>
 <dependency>
 <groupId>org.hamcrest</groupId>
 <artifactId>hamcrest-all</artifactId>
 <version>${hamcrest.version}</version>
 <scope>test</scope>
 </dependency> <dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>${junit.version}</version>
 <exclusions>
 <exclusion>
 <groupId>org.hamcrest</groupId>
 <artifactId>hamcrest-core</artifactId>
 </exclusion>
 </exclusions>
 </dependency>
 <dependency>
 <groupId>org.hsqldb</groupId>
 <artifactId>hsqldb</artifactId>
 <version>${hsqldb.version}</version>
 <scope>test</scope>
 </dependency>
  • 45. Spring - REST service testing @RunWith(SpringJUnit4ClassRunner.class)
 @WebAppConfiguration
 @ContextConfiguration("classpath*:/applicationContext.xml")
 public abstract class BaseControllerTests {
 } public class FighterRestControllerTests extends BaseControllerTests {
 
 private MockMvc mockMvc;
 
 @Autowired
 private WebApplicationContext wac;
 
 @Before
 public void setup() {
 this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
 }
 
 @Test
 public void getAllFightersMethodWorksOK() throws Exception {
 mockMvc.perform(get("/fighters/all")) .andExpect(status().isOk())
 .andExpect(content().contentType(MediaType.APPLICATION_JSON))
 .andExpect(content().string(allOf(containsString("{"id":1,"name":"Mert","lastname": "Caliskan","nickname":"mulderbaba","birthDate":"1980-12-14"}"))));
 }
 }

  • 46. Books on Amazon stackoverflow
  • 47. Release Timeline 10.2006 v2 v2.5 11.2007 12.2009 12.2011 12.2012 12.2013 09.2014 06.2015 v3 v3.1 v3.2 v4 v4.1 v4.2 Spring Java EE 05.1998 JPE J2EE 1.2 12.1999 09.2001 11.2003 5.2006 12.2009 06.2013 Q3 2016 J2EE 1.3 J2EE 1.4 Java EE 5 Java EE 6 Java EE 7 Java EE 8 slowest iteration, biggest change!
  • 48. FinalVerdict •Spring is cool and so is Java EE. •They are providing the best of breed (v4 & EE7) same motto, different underlying infra. •Java EE is standards designator, if you are starting a new project, better to stick w/ the standards. •If you are into sub-projects of Spring, like -data, -social, -batch, and others like security, leverage the use of Spring. •We are using both and we’re both happy :)
  • 49. All sources are available under •JavaEE7Version: 
 https://github.com/yenerm/FightClub
 •SpringVersion: 
 https://github.com/mulderbaba/FightClub
  • 50. Any questions you have, hmm? @yenerm @mertcal