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?

Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework IntroductionAnuj Singh Rajput
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCFunnelll
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architectureAnurag
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarAbir Mohammad
 
Spring introduction
Spring introductionSpring introduction
Spring introductionManav Prasad
 
Collections In Java
Collections In JavaCollections In Java
Collections In JavaBinoj T E
 
Deep dive into Java security architecture
Deep dive into Java security architectureDeep dive into Java security architecture
Deep dive into Java security architecturePrabath Siriwardena
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressionsLogan Chien
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
Spring Framework - Spring Security
Spring Framework - Spring SecuritySpring Framework - Spring Security
Spring Framework - Spring SecurityDzmitry Naskou
 

Was ist angesagt? (20)

Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework Introduction
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Xke spring boot
Xke spring bootXke spring boot
Xke spring boot
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat Shahriyar
 
Hibernate
HibernateHibernate
Hibernate
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Spring security
Spring securitySpring security
Spring security
 
Java persistence api 2.1
Java persistence api 2.1Java persistence api 2.1
Java persistence api 2.1
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring Security 5
Spring Security 5Spring Security 5
Spring Security 5
 
Deep dive into Java security architecture
Deep dive into Java security architectureDeep dive into Java security architecture
Deep dive into Java security architecture
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring Framework - Spring Security
Spring Framework - Spring SecuritySpring Framework - Spring Security
Spring Framework - Spring Security
 
Core java
Core java Core java
Core java
 

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

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
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
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
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
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Kürzlich hochgeladen (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
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
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
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
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
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!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

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