SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
Josh Long (⻰龙之春)
@starbuxman
joshlong.com
josh.long@springsource.com
slideshare.net/joshlong
github.com/joshlong
http://spring.io

J AVA C O N F I G U R AT I O N D E E P D I V E

WITH
REST DESIGN WITH SPRING

About Josh Long (⻰龙之春)
Spring Developer Advocate
@starbuxman
Jean Claude
van Damme!

| josh.long@springsource.com
Java mascot Duke

some thing’s I’ve authored...
It’s Easy to Use Spring’s Annotations in Your Code

Not confidential. Tell everyone.

3
I want Database Access ... with Hibernate 4 Support
@Service
public class CustomerService {
public Customer getCustomerById( long customerId)
...
}

{

public Customer createCustomer( String firstName, String lastName, Date date){
...
}
}

Not confidential. Tell everyone.

4
I want Database Access ... with Hibernate 4 Support
@Service
public class CustomerService {
@Inject // JSR 330
private SessionFactory sessionFactory;
public Customer createCustomer(String firstName,
String lastName,
Date signupDate) {
Customer customer = new Customer();
customer.setFirstName(firstName);
customer.setLastName(lastName);
customer.setSignupDate(signupDate);
sessionFactory.getCurrentSession().save(customer);
return customer;
}
}

Not confidential. Tell everyone.

5
I want Database Access ... with Hibernate 4 Support
@Service
public class CustomerService {
@Inject
private SessionFactory sessionFactory;
@Transactional
public Customer createCustomer(String firstName,
String lastName,
Date signupDate) {
Customer customer = new Customer();
customer.setFirstName(firstName);
customer.setLastName(lastName);
customer.setSignupDate(signupDate);
sessionFactory.getCurrentSession().save(customer);
return customer;
}
}

Not confidential. Tell everyone.

6
I want Declarative Cache Management...
@Service
public class CustomerService {
@Inject
private SessionFactory sessionFactory;
@Transactional(readOnly = true)
@Cacheable(“customers”)
public Customer getCustomerById( long customerId)
...
}

{

...
}

Not confidential. Tell everyone.

7
I want a RESTful Endpoint...
package org.springsource.examples.spring31.web;
..
@RestController
class CustomerController {
@Inject CustomerService customerService;
@RequestMapping(value = "/customer/{id}" )
Customer customerById( @PathVariable Integer id ) {
return customerService.getCustomerById(id);
}
...
}

Not confidential. Tell everyone.

8
...But Where’d the SessionFactory come from?

Not confidential. Tell everyone.

9
The Spring ApplicationContext
From XML:
public class Main {
public static void main(String [] args) throws Throwable {
ApplicationContext ctx =
new ClassPathXmlApplication( “my-config.xml” );
CustomerService serviceReference = ctx.getBean( CustomerService.class );
Customer customer = serviceReference.createCustomer( "Juergen", "Hoeller");
}
}

From Java Configuration
public class Main {
public static void main(String [] args) throws Throwable {
ApplicationContext ctx =
new AnnotationConfigApplicationContext( ServicesConfiguration.class );
CustomerService serviceReference = ctx.getBean( CustomerService.class );
Customer customer = serviceReference.createCustomer( "Juergen", "Hoeller");
}
}

10
A Quick Primer on Configuration
....
<beans>
<tx:annotation-driven transaction-manager = "txManager" />
<context:component-scan base-package = "org.springsource.examples.spring31.services" />
<context:property-placeholder properties = "config.properties" />
<bean id = "txManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name = "sessionFactory" ref = "sessionFactory" />
</bean>
<bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean">
...
</bean>
<bean id = "dataSource" class = "..SimpleDriverDataSource">
<property name= "userName" value = "${ds.user}"/>
...
</bean>
</beans>

ApplicationContext ctx =
new ClassPathXmlApplication( “service-config.xml” );
Not confidential. Tell everyone.
A Quick Primer on Configuration
....
<beans>
<tx:annotation-driven transaction-manager = "txManager" />
<context:component-scan base-package = "org.springsource.examples.spring31.services" />
<context:property-placeholder properties = "config.properties" />
<bean id = "txManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name = "sessionFactory" ref = "sessionFactory" />
</bean>
<bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean">
...
</bean>
<bean id = "dataSource" class = "..SimpleDriverDataSource">
<property name= "userName" value = "${ds.user}"/>
...
</bean>
</beans>

ApplicationContext ctx =
new ClassPathXmlApplication( “service-config.xml” );
Not confidential. Tell everyone.
A Quick Primer on Configuration

@Configuration
@PropertySource("/config.properties")
@EnableTransactionManagement
@ComponentScan(basePackageClasses = {CustomerService.class})
public class ServicesConfiguration {
@Inject private Environment environment;
@Bean
public PlatformTransactionManager txManager() throws Exception {
return new HibernateTransactionManager(this.sessionFactory());
}
@Bean
public SessionFactory sessionFactory() { ... }
@Bean
public DataSource dataSource(){
SimpleDriverDataSource sds = new SimpleDriverDataSource();
sds.setUserName( this.environment.getProperty( “ds.user”));
// ...
return sds;
}
}

ApplicationContext ctx =
new AnnotationConfigApplicationContext( ServicesConfiguration.class );
Not confidential. Tell everyone.
A Quick Primer on Configuration
....
<beans>
<tx:annotation-driven transaction-manager = "txManager" />
<context:component-scan base-package = "org.springsource.examples.spring31.services" />
<context:property-placeholder properties = "config.properties" />
<bean id = "txManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name = "sessionFactory" ref = "sessionFactory" />
</bean>
<bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean">
...
</bean>
<bean id = "dataSource" class = "..SimpleDriverDataSource">
<property name= "userName" value = "${ds.user}"/>
...
</bean>
</beans>

ApplicationContext ctx =
new ClassPathXmlApplication( “service-config.xml” );
Not confidential. Tell everyone.
A Quick Primer on Configuration

@Configuration
@PropertySource("/config.properties")
@EnableTransactionManagement
@ComponentScan(basePackageClasses = {CustomerService.class})
public class ServicesConfiguration {
@Inject private Environment environment;
@Bean
public PlatformTransactionManager txManager() throws Exception {
return new HibernateTransactionManager(this.sessionFactory());
}
@Bean
public SessionFactory sessionFactory() { ... }
@Bean
public DataSource dataSource(){
SimpleDriverDataSource sds = new SimpleDriverDataSource();
sds.setUserName( this.environment.getProperty( “ds.user”));
// ...
return sds;
}
}

ApplicationContext ctx =
new AnnotationConfigApplicationContext( ServicesConfiguration.class );
Not confidential. Tell everyone.
A Quick Primer on Configuration : Tangent on Injection

@Configuration
@PropertySource("/config.properties")
@EnableTransactionManagement
@ComponentScan(basePackageClasses = {CustomerService.class})
public class ServicesConfiguration {
@Inject private Environment environment;
@Bean
public PlatformTransactionManager txManager() throws Exception {
return new HibernateTransactionManager(this.sessionFactory());
}
@Bean
public SessionFactory sessionFactory() { ... }
@Bean
public DataSource dataSource(){
SimpleDriverDataSource sds = new SimpleDriverDataSource();
sds.setUserName( this.environment.getProperty( “ds.user”));
// ...
return sds;
}
}

ApplicationContext ctx =
new AnnotationConfigApplicationContext( ServicesConfiguration.class );
Not confidential. Tell everyone.
A Quick Primer on Configuration : Tangent on Injection

@Configuration
@PropertySource("/config.properties")
@EnableTransactionManagement
@ComponentScan(basePackageClasses = {CustomerService.class})
public class ServicesConfiguration {
@Inject private Environment environment;
@Bean
public PlatformTransactionManager txManager( SessionFactory sessionFactory ) throws Exception {
return new HibernateTransactionManager( sessionFactory );
}
@Bean
public SessionFactory sessionFactory() { ... }
@Bean
public DataSource dataSource(){
SimpleDriverDataSource sds = new SimpleDriverDataSource();
sds.setUserName( this.environment.getProperty( “ds.user”));
// ...
return sds;
}
}

ApplicationContext ctx =
new AnnotationConfigApplicationContext( ServicesConfiguration.class );
Not confidential. Tell everyone.
A Quick Primer on Configuration
....
<beans>
<tx:annotation-driven transaction-manager = "txManager" />
<context:component-scan base-package = "org.springsource.examples.spring31.services" />
<context:property-placeholder properties = "config.properties" />
<bean id = "txManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name = "sessionFactory" ref = "sessionFactory" />
</bean>
<bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean">
...
</bean>
<bean id = "dataSource" class = "..SimpleDriverDataSource">
<property name= "userName" value = "${ds.user}"/>
...
</bean>
</beans>

ApplicationContext ctx =
new ClassPathXmlApplication( “service-config.xml” );
Not confidential. Tell everyone.
A Quick Primer on Configuration

@Configuration
@PropertySource("/config.properties")
@EnableTransactionManagement
@ComponentScan (basePackageClasses = {CustomerService.class})
public class ServicesConfiguration {
@Inject private Environment environment;
@Bean
public PlatformTransactionManager txManager() throws Exception {
return new HibernateTransactionManager(this.sessionFactory());
}
@Bean
public SessionFactory sessionFactory() { ... }
@Bean
public DataSource dataSource(){
SimpleDriverDataSource sds = new SimpleDriverDataSource();
sds.setUserName( this.environment.getProperty( “ds.user”));
// ...
return sds;
}
}

ApplicationContext ctx =
new AnnotationConfigApplicationContext( ServicesConfiguration.class );
Not confidential. Tell everyone.
A Quick Primer on Configuration
....
<beans>
<tx:annotation-driven transaction-manager = "txManager" />
<context:component-scan base-package = "org.springsource.examples.spring31.services" />
<context:property-placeholder properties = "config.properties" />
<bean id = "txManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name = "sessionFactory" ref = "sessionFactory" />
</bean>
<bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean">
...
</bean>
<bean id = "dataSource" class = "..SimpleDriverDataSource">
<property name= "userName" value = "${ds.user}"/>
...
</bean>
</beans>

ApplicationContext ctx =
new ClassPathXmlApplication( “service-config.xml” );
Not confidential. Tell everyone.
A Quick Primer on Configuration

@Configuration
@PropertySource("/config.properties")
@EnableTransactionManagement
@ComponentScan(basePackageClasses = {CustomerService.class})
public class ServicesConfiguration {
@Inject private Environment environment;
@Bean
public PlatformTransactionManager txManager() throws Exception {
return new HibernateTransactionManager(this.sessionFactory());
}
@Bean
public SessionFactory sessionFactory() { ... }
@Bean
public DataSource dataSource(){
SimpleDriverDataSource sds = new SimpleDriverDataSource();
sds.setUserName( this.environment.getProperty( “ds.user”));
// ...
return sds;
}
}

ApplicationContext ctx =
new AnnotationConfigApplicationContext( ServicesConfiguration.class );
Not confidential. Tell everyone.
A Quick Primer on Configuration
....
<beans>
<tx:annotation-driven transaction-manager = "txManager" />
<context:component-scan base-package = "org.springsource.examples.spring31.services" />
<context:property-placeholder properties = "config.properties" />
<bean id = "txManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name = "sessionFactory" ref = "sessionFactory" />
</bean>
<bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean">
...
</bean>
<bean id = "dataSource" class = "..SimpleDriverDataSource">
<property name= "userName" value = "${ds.user}"/>
...
</bean>
</beans>

ApplicationContext ctx =
new ClassPathXmlApplication( “service-config.xml” );
Not confidential. Tell everyone.
A Quick Primer on Configuration

@Configuration
@PropertySource("/config.properties")
@EnableTransactionManagement
@ComponentScan(basePackageClasses = {CustomerService.class})
public class ServicesConfiguration {
@Inject private Environment environment;
@Bean
public PlatformTransactionManager txManager() throws Exception {
return new HibernateTransactionManager(this.sessionFactory());
}
@Bean
public SessionFactory sessionFactory() { ... }
@Bean
public DataSource dataSource(){
SimpleDriverDataSource sds = new SimpleDriverDataSource();
sds.setUserName( this.environment.getProperty( “ds.user”));
// ...
return sds;
}
}

ApplicationContext ctx =
new AnnotationConfigApplicationContext( ServicesConfiguration.class );
Not confidential. Tell everyone.
Test Context Framework
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
loader=AnnotationConfigContextLoader.class,
classes={TransferServiceConfig.class, DataConfig.class})
@ActiveProfiles("dev")
public class TransferServiceTest {
@Autowired
private TransferService transferService;
@Test
public void testTransferService() {
...
}
}

24
REST DESIGN WITH SPRING

@starbuxman
josh.long@springsource.com
josh@joshlong.com
github.com/joshlong
slideshare.net/joshlong

Any

?

Questions

Mais conteúdo relacionado

Mais procurados

Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Masoud Kalali
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup PerformanceGreg Whalin
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup PerformanceJustin Cataldo
 
Getting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsGetting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsArun Gupta
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/ServletSunil OS
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsCarol McDonald
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gearsdion
 
Simple REST with Dropwizard
Simple REST with DropwizardSimple REST with Dropwizard
Simple REST with DropwizardAndrei Savu
 
Multi client Development with Spring
Multi client Development with SpringMulti client Development with Spring
Multi client Development with SpringJoshua Long
 
Building a Backend with Flask
Building a Backend with FlaskBuilding a Backend with Flask
Building a Backend with FlaskMake School
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDBMongoDB
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPAFaren faren
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play FrameworkKnoldus Inc.
 
CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2Geoffrey Fox
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and FriendsYun Zhi Lin
 

Mais procurados (19)

Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
 
Spring 4 - A&BP CC
Spring 4 - A&BP CCSpring 4 - A&BP CC
Spring 4 - A&BP CC
 
Spring Mvc Rest
Spring Mvc RestSpring Mvc Rest
Spring Mvc Rest
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
Getting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsGetting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent Events
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
Angular beans
Angular beansAngular beans
Angular beans
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
 
Simple REST with Dropwizard
Simple REST with DropwizardSimple REST with Dropwizard
Simple REST with Dropwizard
 
Multi client Development with Spring
Multi client Development with SpringMulti client Development with Spring
Multi client Development with Spring
 
Building a Backend with Flask
Building a Backend with FlaskBuilding a Backend with Flask
Building a Backend with Flask
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPA
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play Framework
 
CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
 

Semelhante a Java Configuration Deep Dive with Spring

Spring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenSpring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenJoshua Long
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Paco de la Cruz
 
Implement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyoImplement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyoToshiaki Maki
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsAleksandar Ilić
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsPSTechSerbia
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EEAlexis Hassler
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the TrenchesJonathan Wage
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networkingVitali Pekelis
 
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012hwilming
 
Spring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud FoundrySpring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud FoundryJoshua Long
 
Test your microservices with REST-Assured
Test your microservices with REST-AssuredTest your microservices with REST-Assured
Test your microservices with REST-AssuredMichel Schudel
 
Modern Android app library stack
Modern Android app library stackModern Android app library stack
Modern Android app library stackTomáš Kypta
 
Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Paco de la Cruz
 
A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom Joshua Long
 
Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WAREFermin Galan
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasyJBug Italy
 
Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps OfflinePedro Morais
 

Semelhante a Java Configuration Deep Dive with Spring (20)

Spring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenSpring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in Heaven
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)
 
Implement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyoImplement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyo
 
Dropwizard
DropwizardDropwizard
Dropwizard
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App Components
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App Components
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networking
 
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012
 
Spring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud FoundrySpring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud Foundry
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
Test your microservices with REST-Assured
Test your microservices with REST-AssuredTest your microservices with REST-Assured
Test your microservices with REST-Assured
 
Modern Android app library stack
Modern Android app library stackModern Android app library stack
Modern Android app library stack
 
Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30)
 
A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom
 
Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps Offline
 

Mais de Joshua Long

Bootiful Code with Spring Boot
Bootiful Code with Spring BootBootiful Code with Spring Boot
Bootiful Code with Spring BootJoshua Long
 
Microservices with Spring Boot
Microservices with Spring BootMicroservices with Spring Boot
Microservices with Spring BootJoshua Long
 
the Spring Update from JavaOne 2013
the Spring Update from JavaOne 2013the Spring Update from JavaOne 2013
the Spring Update from JavaOne 2013Joshua Long
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
The spring 32 update final
The spring 32 update finalThe spring 32 update final
The spring 32 update finalJoshua Long
 
Integration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud FoundryIntegration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud FoundryJoshua Long
 
using Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud Foundryusing Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud FoundryJoshua Long
 
Spring in-the-cloud
Spring in-the-cloudSpring in-the-cloud
Spring in-the-cloudJoshua Long
 
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
The Cloud Foundry bootcamp talk from SpringOne On The Road - EuropeThe Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
The Cloud Foundry bootcamp talk from SpringOne On The Road - EuropeJoshua Long
 
Spring Batch Behind the Scenes
Spring Batch Behind the ScenesSpring Batch Behind the Scenes
Spring Batch Behind the ScenesJoshua Long
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry BootcampJoshua Long
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking TourJoshua Long
 
Extending Spring for Custom Usage
Extending Spring for Custom UsageExtending Spring for Custom Usage
Extending Spring for Custom UsageJoshua Long
 
Using Spring's IOC Model
Using Spring's IOC ModelUsing Spring's IOC Model
Using Spring's IOC ModelJoshua Long
 
Enterprise Integration and Batch Processing on Cloud Foundry
Enterprise Integration and Batch Processing on Cloud FoundryEnterprise Integration and Batch Processing on Cloud Foundry
Enterprise Integration and Batch Processing on Cloud FoundryJoshua Long
 
a Running Tour of Cloud Foundry
a Running Tour of Cloud Foundrya Running Tour of Cloud Foundry
a Running Tour of Cloud FoundryJoshua Long
 
Cloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and VaadinCloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and VaadinJoshua Long
 

Mais de Joshua Long (19)

Bootiful Code with Spring Boot
Bootiful Code with Spring BootBootiful Code with Spring Boot
Bootiful Code with Spring Boot
 
Microservices with Spring Boot
Microservices with Spring BootMicroservices with Spring Boot
Microservices with Spring Boot
 
Boot It Up
Boot It UpBoot It Up
Boot It Up
 
the Spring Update from JavaOne 2013
the Spring Update from JavaOne 2013the Spring Update from JavaOne 2013
the Spring Update from JavaOne 2013
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
The spring 32 update final
The spring 32 update finalThe spring 32 update final
The spring 32 update final
 
Integration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud FoundryIntegration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud Foundry
 
using Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud Foundryusing Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud Foundry
 
Spring in-the-cloud
Spring in-the-cloudSpring in-the-cloud
Spring in-the-cloud
 
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
The Cloud Foundry bootcamp talk from SpringOne On The Road - EuropeThe Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
 
Spring Batch Behind the Scenes
Spring Batch Behind the ScenesSpring Batch Behind the Scenes
Spring Batch Behind the Scenes
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry Bootcamp
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 
Extending Spring for Custom Usage
Extending Spring for Custom UsageExtending Spring for Custom Usage
Extending Spring for Custom Usage
 
Using Spring's IOC Model
Using Spring's IOC ModelUsing Spring's IOC Model
Using Spring's IOC Model
 
Enterprise Integration and Batch Processing on Cloud Foundry
Enterprise Integration and Batch Processing on Cloud FoundryEnterprise Integration and Batch Processing on Cloud Foundry
Enterprise Integration and Batch Processing on Cloud Foundry
 
a Running Tour of Cloud Foundry
a Running Tour of Cloud Foundrya Running Tour of Cloud Foundry
a Running Tour of Cloud Foundry
 
Cloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and VaadinCloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and Vaadin
 
Messaging sz
Messaging szMessaging sz
Messaging sz
 

Último

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Java Configuration Deep Dive with Spring

  • 2. REST DESIGN WITH SPRING About Josh Long (⻰龙之春) Spring Developer Advocate @starbuxman Jean Claude van Damme! | josh.long@springsource.com Java mascot Duke some thing’s I’ve authored...
  • 3. It’s Easy to Use Spring’s Annotations in Your Code Not confidential. Tell everyone. 3
  • 4. I want Database Access ... with Hibernate 4 Support @Service public class CustomerService { public Customer getCustomerById( long customerId) ... } { public Customer createCustomer( String firstName, String lastName, Date date){ ... } } Not confidential. Tell everyone. 4
  • 5. I want Database Access ... with Hibernate 4 Support @Service public class CustomerService { @Inject // JSR 330 private SessionFactory sessionFactory; public Customer createCustomer(String firstName, String lastName, Date signupDate) { Customer customer = new Customer(); customer.setFirstName(firstName); customer.setLastName(lastName); customer.setSignupDate(signupDate); sessionFactory.getCurrentSession().save(customer); return customer; } } Not confidential. Tell everyone. 5
  • 6. I want Database Access ... with Hibernate 4 Support @Service public class CustomerService { @Inject private SessionFactory sessionFactory; @Transactional public Customer createCustomer(String firstName, String lastName, Date signupDate) { Customer customer = new Customer(); customer.setFirstName(firstName); customer.setLastName(lastName); customer.setSignupDate(signupDate); sessionFactory.getCurrentSession().save(customer); return customer; } } Not confidential. Tell everyone. 6
  • 7. I want Declarative Cache Management... @Service public class CustomerService { @Inject private SessionFactory sessionFactory; @Transactional(readOnly = true) @Cacheable(“customers”) public Customer getCustomerById( long customerId) ... } { ... } Not confidential. Tell everyone. 7
  • 8. I want a RESTful Endpoint... package org.springsource.examples.spring31.web; .. @RestController class CustomerController { @Inject CustomerService customerService; @RequestMapping(value = "/customer/{id}" ) Customer customerById( @PathVariable Integer id ) { return customerService.getCustomerById(id); } ... } Not confidential. Tell everyone. 8
  • 9. ...But Where’d the SessionFactory come from? Not confidential. Tell everyone. 9
  • 10. The Spring ApplicationContext From XML: public class Main { public static void main(String [] args) throws Throwable { ApplicationContext ctx = new ClassPathXmlApplication( “my-config.xml” ); CustomerService serviceReference = ctx.getBean( CustomerService.class ); Customer customer = serviceReference.createCustomer( "Juergen", "Hoeller"); } } From Java Configuration public class Main { public static void main(String [] args) throws Throwable { ApplicationContext ctx = new AnnotationConfigApplicationContext( ServicesConfiguration.class ); CustomerService serviceReference = ctx.getBean( CustomerService.class ); Customer customer = serviceReference.createCustomer( "Juergen", "Hoeller"); } } 10
  • 11. A Quick Primer on Configuration .... <beans> <tx:annotation-driven transaction-manager = "txManager" /> <context:component-scan base-package = "org.springsource.examples.spring31.services" /> <context:property-placeholder properties = "config.properties" /> <bean id = "txManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name = "sessionFactory" ref = "sessionFactory" /> </bean> <bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean"> ... </bean> <bean id = "dataSource" class = "..SimpleDriverDataSource"> <property name= "userName" value = "${ds.user}"/> ... </bean> </beans> ApplicationContext ctx = new ClassPathXmlApplication( “service-config.xml” ); Not confidential. Tell everyone.
  • 12. A Quick Primer on Configuration .... <beans> <tx:annotation-driven transaction-manager = "txManager" /> <context:component-scan base-package = "org.springsource.examples.spring31.services" /> <context:property-placeholder properties = "config.properties" /> <bean id = "txManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name = "sessionFactory" ref = "sessionFactory" /> </bean> <bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean"> ... </bean> <bean id = "dataSource" class = "..SimpleDriverDataSource"> <property name= "userName" value = "${ds.user}"/> ... </bean> </beans> ApplicationContext ctx = new ClassPathXmlApplication( “service-config.xml” ); Not confidential. Tell everyone.
  • 13. A Quick Primer on Configuration @Configuration @PropertySource("/config.properties") @EnableTransactionManagement @ComponentScan(basePackageClasses = {CustomerService.class}) public class ServicesConfiguration { @Inject private Environment environment; @Bean public PlatformTransactionManager txManager() throws Exception { return new HibernateTransactionManager(this.sessionFactory()); } @Bean public SessionFactory sessionFactory() { ... } @Bean public DataSource dataSource(){ SimpleDriverDataSource sds = new SimpleDriverDataSource(); sds.setUserName( this.environment.getProperty( “ds.user”)); // ... return sds; } } ApplicationContext ctx = new AnnotationConfigApplicationContext( ServicesConfiguration.class ); Not confidential. Tell everyone.
  • 14. A Quick Primer on Configuration .... <beans> <tx:annotation-driven transaction-manager = "txManager" /> <context:component-scan base-package = "org.springsource.examples.spring31.services" /> <context:property-placeholder properties = "config.properties" /> <bean id = "txManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name = "sessionFactory" ref = "sessionFactory" /> </bean> <bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean"> ... </bean> <bean id = "dataSource" class = "..SimpleDriverDataSource"> <property name= "userName" value = "${ds.user}"/> ... </bean> </beans> ApplicationContext ctx = new ClassPathXmlApplication( “service-config.xml” ); Not confidential. Tell everyone.
  • 15. A Quick Primer on Configuration @Configuration @PropertySource("/config.properties") @EnableTransactionManagement @ComponentScan(basePackageClasses = {CustomerService.class}) public class ServicesConfiguration { @Inject private Environment environment; @Bean public PlatformTransactionManager txManager() throws Exception { return new HibernateTransactionManager(this.sessionFactory()); } @Bean public SessionFactory sessionFactory() { ... } @Bean public DataSource dataSource(){ SimpleDriverDataSource sds = new SimpleDriverDataSource(); sds.setUserName( this.environment.getProperty( “ds.user”)); // ... return sds; } } ApplicationContext ctx = new AnnotationConfigApplicationContext( ServicesConfiguration.class ); Not confidential. Tell everyone.
  • 16. A Quick Primer on Configuration : Tangent on Injection @Configuration @PropertySource("/config.properties") @EnableTransactionManagement @ComponentScan(basePackageClasses = {CustomerService.class}) public class ServicesConfiguration { @Inject private Environment environment; @Bean public PlatformTransactionManager txManager() throws Exception { return new HibernateTransactionManager(this.sessionFactory()); } @Bean public SessionFactory sessionFactory() { ... } @Bean public DataSource dataSource(){ SimpleDriverDataSource sds = new SimpleDriverDataSource(); sds.setUserName( this.environment.getProperty( “ds.user”)); // ... return sds; } } ApplicationContext ctx = new AnnotationConfigApplicationContext( ServicesConfiguration.class ); Not confidential. Tell everyone.
  • 17. A Quick Primer on Configuration : Tangent on Injection @Configuration @PropertySource("/config.properties") @EnableTransactionManagement @ComponentScan(basePackageClasses = {CustomerService.class}) public class ServicesConfiguration { @Inject private Environment environment; @Bean public PlatformTransactionManager txManager( SessionFactory sessionFactory ) throws Exception { return new HibernateTransactionManager( sessionFactory ); } @Bean public SessionFactory sessionFactory() { ... } @Bean public DataSource dataSource(){ SimpleDriverDataSource sds = new SimpleDriverDataSource(); sds.setUserName( this.environment.getProperty( “ds.user”)); // ... return sds; } } ApplicationContext ctx = new AnnotationConfigApplicationContext( ServicesConfiguration.class ); Not confidential. Tell everyone.
  • 18. A Quick Primer on Configuration .... <beans> <tx:annotation-driven transaction-manager = "txManager" /> <context:component-scan base-package = "org.springsource.examples.spring31.services" /> <context:property-placeholder properties = "config.properties" /> <bean id = "txManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name = "sessionFactory" ref = "sessionFactory" /> </bean> <bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean"> ... </bean> <bean id = "dataSource" class = "..SimpleDriverDataSource"> <property name= "userName" value = "${ds.user}"/> ... </bean> </beans> ApplicationContext ctx = new ClassPathXmlApplication( “service-config.xml” ); Not confidential. Tell everyone.
  • 19. A Quick Primer on Configuration @Configuration @PropertySource("/config.properties") @EnableTransactionManagement @ComponentScan (basePackageClasses = {CustomerService.class}) public class ServicesConfiguration { @Inject private Environment environment; @Bean public PlatformTransactionManager txManager() throws Exception { return new HibernateTransactionManager(this.sessionFactory()); } @Bean public SessionFactory sessionFactory() { ... } @Bean public DataSource dataSource(){ SimpleDriverDataSource sds = new SimpleDriverDataSource(); sds.setUserName( this.environment.getProperty( “ds.user”)); // ... return sds; } } ApplicationContext ctx = new AnnotationConfigApplicationContext( ServicesConfiguration.class ); Not confidential. Tell everyone.
  • 20. A Quick Primer on Configuration .... <beans> <tx:annotation-driven transaction-manager = "txManager" /> <context:component-scan base-package = "org.springsource.examples.spring31.services" /> <context:property-placeholder properties = "config.properties" /> <bean id = "txManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name = "sessionFactory" ref = "sessionFactory" /> </bean> <bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean"> ... </bean> <bean id = "dataSource" class = "..SimpleDriverDataSource"> <property name= "userName" value = "${ds.user}"/> ... </bean> </beans> ApplicationContext ctx = new ClassPathXmlApplication( “service-config.xml” ); Not confidential. Tell everyone.
  • 21. A Quick Primer on Configuration @Configuration @PropertySource("/config.properties") @EnableTransactionManagement @ComponentScan(basePackageClasses = {CustomerService.class}) public class ServicesConfiguration { @Inject private Environment environment; @Bean public PlatformTransactionManager txManager() throws Exception { return new HibernateTransactionManager(this.sessionFactory()); } @Bean public SessionFactory sessionFactory() { ... } @Bean public DataSource dataSource(){ SimpleDriverDataSource sds = new SimpleDriverDataSource(); sds.setUserName( this.environment.getProperty( “ds.user”)); // ... return sds; } } ApplicationContext ctx = new AnnotationConfigApplicationContext( ServicesConfiguration.class ); Not confidential. Tell everyone.
  • 22. A Quick Primer on Configuration .... <beans> <tx:annotation-driven transaction-manager = "txManager" /> <context:component-scan base-package = "org.springsource.examples.spring31.services" /> <context:property-placeholder properties = "config.properties" /> <bean id = "txManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name = "sessionFactory" ref = "sessionFactory" /> </bean> <bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean"> ... </bean> <bean id = "dataSource" class = "..SimpleDriverDataSource"> <property name= "userName" value = "${ds.user}"/> ... </bean> </beans> ApplicationContext ctx = new ClassPathXmlApplication( “service-config.xml” ); Not confidential. Tell everyone.
  • 23. A Quick Primer on Configuration @Configuration @PropertySource("/config.properties") @EnableTransactionManagement @ComponentScan(basePackageClasses = {CustomerService.class}) public class ServicesConfiguration { @Inject private Environment environment; @Bean public PlatformTransactionManager txManager() throws Exception { return new HibernateTransactionManager(this.sessionFactory()); } @Bean public SessionFactory sessionFactory() { ... } @Bean public DataSource dataSource(){ SimpleDriverDataSource sds = new SimpleDriverDataSource(); sds.setUserName( this.environment.getProperty( “ds.user”)); // ... return sds; } } ApplicationContext ctx = new AnnotationConfigApplicationContext( ServicesConfiguration.class ); Not confidential. Tell everyone.
  • 24. Test Context Framework @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( loader=AnnotationConfigContextLoader.class, classes={TransferServiceConfig.class, DataConfig.class}) @ActiveProfiles("dev") public class TransferServiceTest { @Autowired private TransferService transferService; @Test public void testTransferService() { ... } } 24
  • 25. REST DESIGN WITH SPRING @starbuxman josh.long@springsource.com josh@joshlong.com github.com/joshlong slideshare.net/joshlong Any ? Questions