SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Java spring framework
Java spring frameworkJava spring framework
Java spring frameworkRajiv Gupta
 
Reactjs workshop (1)
Reactjs workshop (1)Reactjs workshop (1)
Reactjs workshop (1)Ahmed rebai
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depthVinay Kumar
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewShahed Chowdhuri
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootJosué Neis
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painSander Mak (@Sander_Mak)
 
Spring Framework - Data Access
Spring Framework - Data AccessSpring Framework - Data Access
Spring Framework - Data AccessDzmitry Naskou
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJSBrainhub
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework tola99
 
Understanding Sling Models in AEM
Understanding Sling Models in AEMUnderstanding Sling Models in AEM
Understanding Sling Models in AEMAccunity Software
 

Was ist angesagt? (20)

JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Java spring framework
Java spring frameworkJava spring framework
Java spring framework
 
Reactjs workshop (1)
Reactjs workshop (1)Reactjs workshop (1)
Reactjs workshop (1)
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Spring Framework - Data Access
Spring Framework - Data AccessSpring Framework - Data Access
Spring Framework - Data Access
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
Fetch API Talk
Fetch API TalkFetch API Talk
Fetch API Talk
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Understanding Sling Models in AEM
Understanding Sling Models in AEMUnderstanding Sling Models in AEM
Understanding Sling Models in AEM
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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: 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
 
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
 
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
 

Ähnlich wie 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: 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
 
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...
 
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
 

Mehr von 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
 

Mehr von 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?
 

Kürzlich hochgeladen

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Kürzlich hochgeladen (20)

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

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