SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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
 

Tendances (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
 

Similaire à 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
 

Similaire à 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
 

Plus 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
 

Plus 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
 

Dernier

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
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
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
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
 
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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
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
 
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
 
"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
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
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
 

Dernier (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
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
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
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
 
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
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
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!
 
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
 
"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
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
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
 

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