SlideShare a Scribd company logo
1 of 32
Spring and Java EE Side by
Side
Reza Rahman
Java EE/GlassFish Evangelist
Reza.Rahman@Oracle.com
@reza_rahman
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public2
Program Agenda
 Spring and Java EE
 Side-by-Side
 Ecosystems
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public3
A Bird’s Eye View
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public4
Main Features/APIs
• Spring also integrates with EJB 3, but not CDI
• Similar patterns for validation, WebSocket, JSON, XML, SOAP, remoting, scheduling, caching, etc
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public5
Java EE and Spring Component
@Stateless
public class BidService {
@PersistenceContext
private EntityManager entityManager;
public void addBid(Bid bid) {
entityManager.persist(bid);
}
}
@Component
public class BidService {
@PersistenceContext
private EntityManager entityManager;
@Transactional
public void addBid(Bid bid) {
entityManager.persist(bid);
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public6
Spring Bootstrap (XML)
<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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="com.actionbazaar"/>
<tx:annotation-driven/>
...
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>
</beans>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public7
Defining the Data Source
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver"/>
<property name="url"
value="jdbc:oracle:thin:@localhost:1521:actionbazaar"/>
<property name="user" value="scott"/>
<property name="password" value="tiger"/>
</bean>
<data-source>
<name>java:global/jdbc/myDataSource</name>
<class-name>oracle.jdbc.driver.OracleDriver</class-name>
<port-number>1521</port-number>
<server-name>localhost</server-name>
<database-name>actionbazaar</database-name>
<user>scott</user>
<password>tiger</password>
<property>
<name>createDatabase</name>
<value>create</value>
</property>
</data-source>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public8
Spring Bootstrap (Java)
@Configuration
@ComponentScan(basePackages="com.actionbazaar")
@EnableTransactionManagement
public class DataConfiguration {
@Bean(destroyMethod="close")
public DataSource dataSource(){
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
ds.setUrl("jdbc:oracle:thin:@localhost:1521:actionbazaar");
ds.setUser("scott");
ds.setPassword("tiger");
return ds;
}
@Bean
public PlatformTransactionManager transactionManager(){
return new DataSourceTransactionManager(dataSource());
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(){
LocalContainerEntityManagerFactoryBean factory = LocalContainerEntityManagerFactoryBean();
factory.setDataSource(dataSource());
factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
return factory;
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public9
Servlet Bootstrap
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:**/applicationContext*.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
...
</web-app>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public10
Simple JSF Page
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="/WEB-INF/template.xhtml">
<ui:define name="title">Add Bid</ui:define>
<ui:define name="content">
<h3>Add Bid</h3>
<h:form>
<p>Item: <h:outputText value="#{item.name}"/></p>
<p>Current bid:
<h:outputText value="#{item.highestBid.amount}"/></p>
<p>Amount: <h:inputText id="amount" value="#{bid.amount}"/></p>
<p><h:commandButton value="Add bid"
action="#{addBid.onClick}"/></p>
</h:form>
</ui:define>
</ui:composition>
</html>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public11
CDI/JPA Components
CDI Backing Bean JPA Entity
@Named @ViewScoped
public class AddBid {
@Inject private BidService bidService;
@Inject @LoggedIn private User user;
@Inject @SelectedItem private Item item;
@Produces @Named
private Bid bid = new Bid();
public String onClick() {
bid.setBidder(user);
bid.setItem(item);
bidService.addBid(bid);
return “bid_confirm.xhtml”;
}
}
@Entity @Table(name="BIDS")
public class Bid {
@Id @GeneratedValue
private long id;
@ManyToOne(optional=false)
private User bidder;
@ManyToOne(optional=false)
private Item item;
DecimalMin("0.0")
private double amount;
...
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public12
Servlet Bootstrap
<web-app>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public13
Spring MVC JSP Page
<%@ taglib prefix="tiles“
uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="form"
uri="http://www.springframework.org/tags/form" %>
<tiles:insertDefinition name="defaultTemplate">
<tiles:putAttribute name=“title">Add Bid</tiles:putAttribute>
<tiles:putAttribute name=“content">
<h3>Add Bid</h3>
<form:form modelAttribute="bid" method="post">
<p>Item: <form:errors path="item" cssClass="error"/>
${item.name}</p>
<p>Current bid: ${item.highestBid.amount}</p>
<p>Amount: <form:errors path="amount" cssClass="error"/>
<form:input path="amount"/></p>
<p><input type="submit" value="Add Bid">
</form:form>
</tiles:putAttribute>
</tiles:insertDefinition>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public14
Spring MVC Controller
@RequestMapping("/add_bid.do") @SessionAttributes({"item", "bid"})
public class BidController {
@Autowired private ItemService itemService;
@Autowired private BidService bidService;
@RequestMapping(method=RequestMethod.GET)
public String setupForm(@RequestParam("itemId") int itemId, ModelMap model) {
Item item = itemService.getItem(itemId);
model.addAttribute("item", item);
Bid bid = new Bid();
model.addAttribute("bid", bid);
return "add_bid";
}
@RequestMapping(method=RequestMethod.POST)
public String addBid(@ModelAttribute("item") Item item, @Valid @ModelAttribute("bid") Bid bid,
HttpSession session, BindingResult result, SessionStatus status) {
bid.setBidder((User)session.getAttribute("user"));
bid.setItem(item);
if (result.hasErrors()) {
return "add_bid";
} else {
bidService.addBid(bid);
status.setComplete();
return "redirect:confirm_bid.do?itemId=" + item.getItemId();
}
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public15
Spring MVC Bootstrap
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.actionbazaar"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles/tiles-definitions.xml</value>
</list>
</property>
</bean>
</beans>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public16
Servlet Bootstrap
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:**/applicationContext*.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>actionbazaar</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>actionbazaar</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>jsp/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public17
CDI Interceptor
@Stateless
public class BidService {
@Inject private BidRepository bidRepository;
...
@Audited
public void addBid(Bid bid) {
...
bidRepository.saveBid(bid);
}
}
@Interceptor @Audited
public class AuditInterceptor {
@AroundInvoke
public Object audit(InvocationContext context) {
logger.log(Level.INFO, "Executing: {0}",
context.getMethod().getName());
return context.proceed();
}
}
@InterceptorBindingType
@Target({TYPE, METHOD}) @Retention(RUNTIME)
public @interface Audited {}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public18
Spring/AspectJ
@Component
public class BidService {
@Autowired private BidRepository bidRepository;
...
@Audited @Transactional
public void addBid(Bid bid) {
...
bidRepository.saveBid(bid);
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Audited {}
@Component @Aspect
public class AuditAspect {
@Before("execution(public * *(..)) && @annotation(Audited)")
public void audit(JoinPoint joinPoint) {
logger.log(Level.INFO, "Entering: {0}", joinPoint);
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public19
Spring/AspectJ Bootstrap
<beans xmlns="http://www.springframework.org/schema/beans"
...
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
...
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
...
<aop:aspectj-autoproxy/>
...
</beans>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public20
JMS MDB
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destinationLookup",
propertyValue = "java:global/jms/OrderQueue")})
public class OrderProcessor implements MessageListener {
@Inject private OrderService orderService;
public void onMessage(Message message) {
try {
ObjectMessage objectMessage = (ObjectMessage) message;
Order order = (Order) objectMessage.getObject();
orderService.addOrder(order);
} catch (JMSException e) {
e.printStackTrace();
}
}
}
<jms-destination>
<name>java:global/jms/OrderQueue</name>
<interface-name>javax.jms.Queue</interface-name>
<resource-adapter>jmsra</resource-adapter>
<destination-name>OrderQueue</destination-name>
</jms-destination>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public21
Spring JMS Listener
@Component
public class OrderProcessor implements MessageListener {
@Autowired private OrderService orderService;
@Transactional
public void onMessage(Message message) {
try {
ObjectMessage objectMessage = (ObjectMessage) message;
Order order = (Order) objectMessage.getObject();
orderService.addOrder(order);
} catch (JMSException e) {
e.printStackTrace();
}
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public22
Spring Message Listener Bootstrap
<beans xmlns="http://www.springframework.org/schema/beans"
...
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
...
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd">
...
<amq:broker useJmx="false" persistent="false">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://localhost:0" />
</amq:transportConnectors>
</amq:broker>
<amq:queue id="jms/OrderQueue" physicalName="queue.OrderQueue"/>
<amq:connectionFactory id="connectionFactory" brokerURL="vm://localhost"/>
<jms:listener-container transaction-manager="transactionManager"
concurrency="3-5">
<jms:listener destination="jms/OrderQueue" ref="orderProcessor"/>
</jms:listener-container>
</beans>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public23
JMS 2 Message Sender
@Stateless
public class OrderService {
@Inject private JMSContext jmsContext;
@Resource(lookup = "java:global/jms/OrderQueue")
private Destination orderQueue;
...
public void sendOrder(Order order) {
jmsContext.createProducer()
.setPriority(HIGH_PRIORITY)
.setDisableMessageID(true)
.setDisableMessageTimestamp(true)
.send(orderQueue, order);
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public24
Spring JMS Message Sender
@Component
public class OrderService {
private JmsTemplate jmsTemplate;
@Resource(name="jms/OrderQueue")
private Queue queue;
...
@Autowired
public void setConnectionFactory(
ConnectionFactory connectionFactory) {
jmsTemplate = new JmsTemplate(connectionFactory);
}
@Transactional
public void sendOrder(Order order) {
jmsTemplate.setExplicitQosEnabled(true);
jmsTemplate.setPriority(HIGH_PRIORITY);
jmsTemplate.setMessageIdEnabled(false);
jmsTemplate.setMessageTimestampEnabled(false);
jmsTemplate.convertAndsend(queue, order);
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public25
EJB3 and Spring Scheduling
@Stateless
public class NewsLetterGenerator {
...
@Schedule(dayOfMonth="Last Tues",
month="Jan-May, Sep-Nov",
timezone="America/New_York")
public void generateMonthlyNewsLetter() {
...
}
}
@Component
public class NewsLetterGenerator {
...
@Scheduled(
cron="0 0 0 ? JAN-MAY,SEP-NOV 3L")
public void generateMonthlyNewsLetter() {
...
}
}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public26
Spring Scheduling Bootstrap
<beans xmlns="http://www.springframework.org/schema/beans"
...
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
...
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd">
...
<task:annotation-driven scheduler="myScheduler"/>
<task:scheduler id="myScheduler" pool-size="10"/>
</beans>
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public27
Spring Projects
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public28
Java EE Ecosystem
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public29
CDI Ecosystem
Implementations
Weld CanDI
RuntimesPortable
Extensions
Tools
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public30
CDI Extensions
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public31
Decisions, decisions…
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public32
A Bird’s Eye View

More Related Content

What's hot

Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...Edureka!
 
Weblogic application server
Weblogic application serverWeblogic application server
Weblogic application serverAnuj Tomar
 
java 8 new features
java 8 new features java 8 new features
java 8 new features Rohit Verma
 
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...Edureka!
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
Java Virtual Machine (JVM), Difference JDK, JRE & JVM
Java Virtual Machine (JVM), Difference JDK, JRE & JVMJava Virtual Machine (JVM), Difference JDK, JRE & JVM
Java Virtual Machine (JVM), Difference JDK, JRE & JVMshamnasain
 

What's hot (20)

Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
 
Jdk,jre,jvm
Jdk,jre,jvmJdk,jre,jvm
Jdk,jre,jvm
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Weblogic application server
Weblogic application serverWeblogic application server
Weblogic application server
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Spring notes
Spring notesSpring notes
Spring notes
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Java Virtual Machine (JVM), Difference JDK, JRE & JVM
Java Virtual Machine (JVM), Difference JDK, JRE & JVMJava Virtual Machine (JVM), Difference JDK, JRE & JVM
Java Virtual Machine (JVM), Difference JDK, JRE & JVM
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring boot
Spring bootSpring boot
Spring boot
 

Viewers also liked

Lightweight J2EE development using Spring
Lightweight J2EE development using SpringLightweight J2EE development using Spring
Lightweight J2EE development using Springspringbyexample
 
Ejb3 1 Overview Glassfish Webinar 100208
Ejb3 1 Overview Glassfish Webinar 100208Ejb3 1 Overview Glassfish Webinar 100208
Ejb3 1 Overview Glassfish Webinar 100208Eduardo Pelegri-Llopart
 
jVoiD - the enterprise ecommerce Java by Schogini
jVoiD - the enterprise ecommerce Java by SchoginijVoiD - the enterprise ecommerce Java by Schogini
jVoiD - the enterprise ecommerce Java by SchoginiSchogini Systems Pvt Ltd
 
Fun with EJB 3.1 and Open EJB
Fun with EJB 3.1 and Open EJBFun with EJB 3.1 and Open EJB
Fun with EJB 3.1 and Open EJBArun Gupta
 
Lightweight J2EE development with Spring (special for UADEV)
Lightweight J2EE development with Spring (special for UADEV)Lightweight J2EE development with Spring (special for UADEV)
Lightweight J2EE development with Spring (special for UADEV)springbyexample
 
Developing real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and KafkaDeveloping real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and Kafkamarius_bogoevici
 

Viewers also liked (8)

Lightweight J2EE development using Spring
Lightweight J2EE development using SpringLightweight J2EE development using Spring
Lightweight J2EE development using Spring
 
Ejb3 1 Overview Glassfish Webinar 100208
Ejb3 1 Overview Glassfish Webinar 100208Ejb3 1 Overview Glassfish Webinar 100208
Ejb3 1 Overview Glassfish Webinar 100208
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
 
jVoiD - the enterprise ecommerce Java by Schogini
jVoiD - the enterprise ecommerce Java by SchoginijVoiD - the enterprise ecommerce Java by Schogini
jVoiD - the enterprise ecommerce Java by Schogini
 
Fun with EJB 3.1 and Open EJB
Fun with EJB 3.1 and Open EJBFun with EJB 3.1 and Open EJB
Fun with EJB 3.1 and Open EJB
 
Tu1 1 5l
Tu1 1 5lTu1 1 5l
Tu1 1 5l
 
Lightweight J2EE development with Spring (special for UADEV)
Lightweight J2EE development with Spring (special for UADEV)Lightweight J2EE development with Spring (special for UADEV)
Lightweight J2EE development with Spring (special for UADEV)
 
Developing real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and KafkaDeveloping real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and Kafka
 

Similar to Java EE and Spring Side-by-Side

Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdfShaiAlmog1
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Max Andersen
 
112815 java ee8_davidd
112815 java ee8_davidd112815 java ee8_davidd
112815 java ee8_daviddTakashi Ito
 
Prairie DevCon 2015 - Crafting Evolvable API Responses
Prairie DevCon 2015 - Crafting Evolvable API ResponsesPrairie DevCon 2015 - Crafting Evolvable API Responses
Prairie DevCon 2015 - Crafting Evolvable API Responsesdarrelmiller71
 
Andy Bosch - JavaServer Faces in the cloud
Andy Bosch -  JavaServer Faces in the cloudAndy Bosch -  JavaServer Faces in the cloud
Andy Bosch - JavaServer Faces in the cloudAndy Bosch
 
Salesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web ComponentSalesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web ComponentAccenture Hungary
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2Paras Mendiratta
 
Hi5 Hackathon Presentation
Hi5 Hackathon PresentationHi5 Hackathon Presentation
Hi5 Hackathon PresentationLou Moore
 
Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4Darwin Biler
 
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...jaxLondonConference
 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Arun Gupta
 
SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015Pushkar Chivate
 
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsData Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsRapidValue
 
A resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangleA resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangleAkihito Koriyama
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep DiveGabriel Walt
 
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun GuptaJAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun GuptaJAX London
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSUFYAN SATTAR
 

Similar to Java EE and Spring Side-by-Side (20)

Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdf
 
Java ee7 1hour
Java ee7 1hourJava ee7 1hour
Java ee7 1hour
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
 
112815 java ee8_davidd
112815 java ee8_davidd112815 java ee8_davidd
112815 java ee8_davidd
 
Prairie DevCon 2015 - Crafting Evolvable API Responses
Prairie DevCon 2015 - Crafting Evolvable API ResponsesPrairie DevCon 2015 - Crafting Evolvable API Responses
Prairie DevCon 2015 - Crafting Evolvable API Responses
 
Andy Bosch - JavaServer Faces in the cloud
Andy Bosch -  JavaServer Faces in the cloudAndy Bosch -  JavaServer Faces in the cloud
Andy Bosch - JavaServer Faces in the cloud
 
Salesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web ComponentSalesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web Component
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2
 
Hi5 Hackathon Presentation
Hi5 Hackathon PresentationHi5 Hackathon Presentation
Hi5 Hackathon Presentation
 
Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4
 
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5
 
SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015
 
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsData Seeding via Parameterized API Requests
Data Seeding via Parameterized API Requests
 
A resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangleA resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangle
 
Sightly_techInsight
Sightly_techInsightSightly_techInsight
Sightly_techInsight
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun GuptaJAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
 
CDI @javaonehyderabad
CDI @javaonehyderabadCDI @javaonehyderabad
CDI @javaonehyderabad
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
 

More from Reza Rahman

IBM WebSphere Family on Azure
IBM WebSphere Family on AzureIBM WebSphere Family on Azure
IBM WebSphere Family on AzureReza Rahman
 
Why Java/Jakarta EE Developers are First-Class Citizens on Azure
Why Java/Jakarta EE Developers are First-Class Citizens on AzureWhy Java/Jakarta EE Developers are First-Class Citizens on Azure
Why Java/Jakarta EE Developers are First-Class Citizens on AzureReza Rahman
 
Running WebLogic on Azure Kubernetes and Virtual Machines
Running WebLogic on Azure Kubernetes and Virtual MachinesRunning WebLogic on Azure Kubernetes and Virtual Machines
Running WebLogic on Azure Kubernetes and Virtual MachinesReza Rahman
 
Powering Java on Azure with JBoss EAP
Powering Java on Azure with JBoss EAPPowering Java on Azure with JBoss EAP
Powering Java on Azure with JBoss EAPReza Rahman
 
Down-to-Earth Microservices with Java EE
Down-to-Earth Microservices with Java EEDown-to-Earth Microservices with Java EE
Down-to-Earth Microservices with Java EEReza Rahman
 
Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!Reza Rahman
 
Testing Java EE Applications Using Arquillian
Testing Java EE Applications Using ArquillianTesting Java EE Applications Using Arquillian
Testing Java EE Applications Using ArquillianReza Rahman
 
JavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great MatchJavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great MatchReza Rahman
 
Have You Seen Java EE Lately?
Have You Seen Java EE Lately?Have You Seen Java EE Lately?
Have You Seen Java EE Lately?Reza Rahman
 

More from Reza Rahman (9)

IBM WebSphere Family on Azure
IBM WebSphere Family on AzureIBM WebSphere Family on Azure
IBM WebSphere Family on Azure
 
Why Java/Jakarta EE Developers are First-Class Citizens on Azure
Why Java/Jakarta EE Developers are First-Class Citizens on AzureWhy Java/Jakarta EE Developers are First-Class Citizens on Azure
Why Java/Jakarta EE Developers are First-Class Citizens on Azure
 
Running WebLogic on Azure Kubernetes and Virtual Machines
Running WebLogic on Azure Kubernetes and Virtual MachinesRunning WebLogic on Azure Kubernetes and Virtual Machines
Running WebLogic on Azure Kubernetes and Virtual Machines
 
Powering Java on Azure with JBoss EAP
Powering Java on Azure with JBoss EAPPowering Java on Azure with JBoss EAP
Powering Java on Azure with JBoss EAP
 
Down-to-Earth Microservices with Java EE
Down-to-Earth Microservices with Java EEDown-to-Earth Microservices with Java EE
Down-to-Earth Microservices with Java EE
 
Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!
 
Testing Java EE Applications Using Arquillian
Testing Java EE Applications Using ArquillianTesting Java EE Applications Using Arquillian
Testing Java EE Applications Using Arquillian
 
JavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great MatchJavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great Match
 
Have You Seen Java EE Lately?
Have You Seen Java EE Lately?Have You Seen Java EE Lately?
Have You Seen Java EE Lately?
 

Recently uploaded

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Recently uploaded (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Java EE and Spring Side-by-Side

  • 1. Spring and Java EE Side by Side Reza Rahman Java EE/GlassFish Evangelist Reza.Rahman@Oracle.com @reza_rahman
  • 2. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public2 Program Agenda  Spring and Java EE  Side-by-Side  Ecosystems
  • 3. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public3 A Bird’s Eye View
  • 4. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public4 Main Features/APIs • Spring also integrates with EJB 3, but not CDI • Similar patterns for validation, WebSocket, JSON, XML, SOAP, remoting, scheduling, caching, etc
  • 5. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public5 Java EE and Spring Component @Stateless public class BidService { @PersistenceContext private EntityManager entityManager; public void addBid(Bid bid) { entityManager.persist(bid); } } @Component public class BidService { @PersistenceContext private EntityManager entityManager; @Transactional public void addBid(Bid bid) { entityManager.persist(bid); } }
  • 6. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public6 Spring Bootstrap (XML) <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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <context:component-scan base-package="com.actionbazaar"/> <tx:annotation-driven/> ... <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/> </property> </bean> </beans>
  • 7. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public7 Defining the Data Source <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> <property name="url" value="jdbc:oracle:thin:@localhost:1521:actionbazaar"/> <property name="user" value="scott"/> <property name="password" value="tiger"/> </bean> <data-source> <name>java:global/jdbc/myDataSource</name> <class-name>oracle.jdbc.driver.OracleDriver</class-name> <port-number>1521</port-number> <server-name>localhost</server-name> <database-name>actionbazaar</database-name> <user>scott</user> <password>tiger</password> <property> <name>createDatabase</name> <value>create</value> </property> </data-source>
  • 8. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public8 Spring Bootstrap (Java) @Configuration @ComponentScan(basePackages="com.actionbazaar") @EnableTransactionManagement public class DataConfiguration { @Bean(destroyMethod="close") public DataSource dataSource(){ BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("oracle.jdbc.driver.OracleDriver"); ds.setUrl("jdbc:oracle:thin:@localhost:1521:actionbazaar"); ds.setUser("scott"); ds.setPassword("tiger"); return ds; } @Bean public PlatformTransactionManager transactionManager(){ return new DataSourceTransactionManager(dataSource()); } @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory(){ LocalContainerEntityManagerFactoryBean factory = LocalContainerEntityManagerFactoryBean(); factory.setDataSource(dataSource()); factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); return factory; } }
  • 9. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public9 Servlet Bootstrap <web-app> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:**/applicationContext*.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> ... </web-app>
  • 10. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public10 Simple JSF Page <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <ui:composition template="/WEB-INF/template.xhtml"> <ui:define name="title">Add Bid</ui:define> <ui:define name="content"> <h3>Add Bid</h3> <h:form> <p>Item: <h:outputText value="#{item.name}"/></p> <p>Current bid: <h:outputText value="#{item.highestBid.amount}"/></p> <p>Amount: <h:inputText id="amount" value="#{bid.amount}"/></p> <p><h:commandButton value="Add bid" action="#{addBid.onClick}"/></p> </h:form> </ui:define> </ui:composition> </html>
  • 11. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public11 CDI/JPA Components CDI Backing Bean JPA Entity @Named @ViewScoped public class AddBid { @Inject private BidService bidService; @Inject @LoggedIn private User user; @Inject @SelectedItem private Item item; @Produces @Named private Bid bid = new Bid(); public String onClick() { bid.setBidder(user); bid.setItem(item); bidService.addBid(bid); return “bid_confirm.xhtml”; } } @Entity @Table(name="BIDS") public class Bid { @Id @GeneratedValue private long id; @ManyToOne(optional=false) private User bidder; @ManyToOne(optional=false) private Item item; DecimalMin("0.0") private double amount; ... }
  • 12. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public12 Servlet Bootstrap <web-app> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.xhtml</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.xhtml</welcome-file> </welcome-file-list> </web-app>
  • 13. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public13 Spring MVC JSP Page <%@ taglib prefix="tiles“ uri="http://tiles.apache.org/tags-tiles" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <tiles:insertDefinition name="defaultTemplate"> <tiles:putAttribute name=“title">Add Bid</tiles:putAttribute> <tiles:putAttribute name=“content"> <h3>Add Bid</h3> <form:form modelAttribute="bid" method="post"> <p>Item: <form:errors path="item" cssClass="error"/> ${item.name}</p> <p>Current bid: ${item.highestBid.amount}</p> <p>Amount: <form:errors path="amount" cssClass="error"/> <form:input path="amount"/></p> <p><input type="submit" value="Add Bid"> </form:form> </tiles:putAttribute> </tiles:insertDefinition>
  • 14. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public14 Spring MVC Controller @RequestMapping("/add_bid.do") @SessionAttributes({"item", "bid"}) public class BidController { @Autowired private ItemService itemService; @Autowired private BidService bidService; @RequestMapping(method=RequestMethod.GET) public String setupForm(@RequestParam("itemId") int itemId, ModelMap model) { Item item = itemService.getItem(itemId); model.addAttribute("item", item); Bid bid = new Bid(); model.addAttribute("bid", bid); return "add_bid"; } @RequestMapping(method=RequestMethod.POST) public String addBid(@ModelAttribute("item") Item item, @Valid @ModelAttribute("bid") Bid bid, HttpSession session, BindingResult result, SessionStatus status) { bid.setBidder((User)session.getAttribute("user")); bid.setItem(item); if (result.hasErrors()) { return "add_bid"; } else { bidService.addBid(bid); status.setComplete(); return "redirect:confirm_bid.do?itemId=" + item.getItemId(); } } }
  • 15. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public15 Spring MVC Bootstrap <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <mvc:annotation-driven/> <context:component-scan base-package="com.actionbazaar"/> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"> <property name="definitions"> <list> <value>/WEB-INF/tiles/tiles-definitions.xml</value> </list> </property> </bean> </beans>
  • 16. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public16 Servlet Bootstrap <web-app> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:**/applicationContext*.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>actionbazaar</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>actionbazaar</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>jsp/index.jsp</welcome-file> </welcome-file-list> </web-app>
  • 17. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public17 CDI Interceptor @Stateless public class BidService { @Inject private BidRepository bidRepository; ... @Audited public void addBid(Bid bid) { ... bidRepository.saveBid(bid); } } @Interceptor @Audited public class AuditInterceptor { @AroundInvoke public Object audit(InvocationContext context) { logger.log(Level.INFO, "Executing: {0}", context.getMethod().getName()); return context.proceed(); } } @InterceptorBindingType @Target({TYPE, METHOD}) @Retention(RUNTIME) public @interface Audited {}
  • 18. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public18 Spring/AspectJ @Component public class BidService { @Autowired private BidRepository bidRepository; ... @Audited @Transactional public void addBid(Bid bid) { ... bidRepository.saveBid(bid); } } @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Audited {} @Component @Aspect public class AuditAspect { @Before("execution(public * *(..)) && @annotation(Audited)") public void audit(JoinPoint joinPoint) { logger.log(Level.INFO, "Entering: {0}", joinPoint); } }
  • 19. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public19 Spring/AspectJ Bootstrap <beans xmlns="http://www.springframework.org/schema/beans" ... xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans ... http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> ... <aop:aspectj-autoproxy/> ... </beans>
  • 20. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public20 JMS MDB @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "java:global/jms/OrderQueue")}) public class OrderProcessor implements MessageListener { @Inject private OrderService orderService; public void onMessage(Message message) { try { ObjectMessage objectMessage = (ObjectMessage) message; Order order = (Order) objectMessage.getObject(); orderService.addOrder(order); } catch (JMSException e) { e.printStackTrace(); } } } <jms-destination> <name>java:global/jms/OrderQueue</name> <interface-name>javax.jms.Queue</interface-name> <resource-adapter>jmsra</resource-adapter> <destination-name>OrderQueue</destination-name> </jms-destination>
  • 21. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public21 Spring JMS Listener @Component public class OrderProcessor implements MessageListener { @Autowired private OrderService orderService; @Transactional public void onMessage(Message message) { try { ObjectMessage objectMessage = (ObjectMessage) message; Order order = (Order) objectMessage.getObject(); orderService.addOrder(order); } catch (JMSException e) { e.printStackTrace(); } } }
  • 22. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public22 Spring Message Listener Bootstrap <beans xmlns="http://www.springframework.org/schema/beans" ... xmlns:jms="http://www.springframework.org/schema/jms" xmlns:amq="http://activemq.apache.org/schema/core" xsi:schemaLocation="http://www.springframework.org/schema/beans ... http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> ... <amq:broker useJmx="false" persistent="false"> <amq:transportConnectors> <amq:transportConnector uri="tcp://localhost:0" /> </amq:transportConnectors> </amq:broker> <amq:queue id="jms/OrderQueue" physicalName="queue.OrderQueue"/> <amq:connectionFactory id="connectionFactory" brokerURL="vm://localhost"/> <jms:listener-container transaction-manager="transactionManager" concurrency="3-5"> <jms:listener destination="jms/OrderQueue" ref="orderProcessor"/> </jms:listener-container> </beans>
  • 23. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public23 JMS 2 Message Sender @Stateless public class OrderService { @Inject private JMSContext jmsContext; @Resource(lookup = "java:global/jms/OrderQueue") private Destination orderQueue; ... public void sendOrder(Order order) { jmsContext.createProducer() .setPriority(HIGH_PRIORITY) .setDisableMessageID(true) .setDisableMessageTimestamp(true) .send(orderQueue, order); } }
  • 24. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public24 Spring JMS Message Sender @Component public class OrderService { private JmsTemplate jmsTemplate; @Resource(name="jms/OrderQueue") private Queue queue; ... @Autowired public void setConnectionFactory( ConnectionFactory connectionFactory) { jmsTemplate = new JmsTemplate(connectionFactory); } @Transactional public void sendOrder(Order order) { jmsTemplate.setExplicitQosEnabled(true); jmsTemplate.setPriority(HIGH_PRIORITY); jmsTemplate.setMessageIdEnabled(false); jmsTemplate.setMessageTimestampEnabled(false); jmsTemplate.convertAndsend(queue, order); } }
  • 25. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public25 EJB3 and Spring Scheduling @Stateless public class NewsLetterGenerator { ... @Schedule(dayOfMonth="Last Tues", month="Jan-May, Sep-Nov", timezone="America/New_York") public void generateMonthlyNewsLetter() { ... } } @Component public class NewsLetterGenerator { ... @Scheduled( cron="0 0 0 ? JAN-MAY,SEP-NOV 3L") public void generateMonthlyNewsLetter() { ... } }
  • 26. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public26 Spring Scheduling Bootstrap <beans xmlns="http://www.springframework.org/schema/beans" ... xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans ... http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"> ... <task:annotation-driven scheduler="myScheduler"/> <task:scheduler id="myScheduler" pool-size="10"/> </beans>
  • 27. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public27 Spring Projects
  • 28. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public28 Java EE Ecosystem
  • 29. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public29 CDI Ecosystem Implementations Weld CanDI RuntimesPortable Extensions Tools
  • 30. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public30 CDI Extensions
  • 31. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public31 Decisions, decisions…
  • 32. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public32 A Bird’s Eye View