SlideShare una empresa de Scribd logo
1 de 20
© 2012 SpringSource, A division of VMware. All rights reserved
www.springsource.org
Spring 4 Embracing Groovy – A Work in Progress
Jürgen Höller, Principal Engineer, SpringSource
22www.springsource.org
Review: Spring 3 Component Model Themes
 Powerful annotated component model
• stereotypes, configuration classes, composable annotations
 Spring Expression Language
• and its use in value injection
 Comprehensive REST support
• and other Spring @MVC additions
 Support for async MVC processing
• Spring MVC interacting with Servlet 3.0 async callbacks
 Declarative validation and formatting
• integration with JSR-303 Bean Validation
 Declarative scheduling
• trigger abstraction, cron support
 Declarative caching
33www.springsource.org
A Typical Annotated Component
@Service
public class MyBookAdminService implements BookAdminService {
@Inject
public MyBookAdminService(AccountRepository ar) {
…
}
@Transactional
public BookUpdate updateBook(Addendum addendum) {
…
}
}
44www.springsource.org
Configuration Classes
@Configuration
public class MyBookAdminConfig {
@Bean
public BookAdminService myBookAdminService() {
MyBookAdminService service = new MyBookAdminService();
service.setDataSource(bookAdminDataSource());
return service;
}
@Bean
public DataSource bookAdminDataSource() {
…
}
}
55www.springsource.org
Next Stop: Spring Framework 4.0
 First-class support for Java 8 language and API features
• lambda expressions
• JSR-310 Date and Time
• java.util.concurrency updates
 First-class support for Groovy (in particular: Groovy 2)
• Groovy-based bean definitions (a.k.a. Grails Bean Builder)
• AOP treatment for Groovy classes
 A WebSocket endpoint model along the lines of Spring MVC
• deploying Spring-defined endpoint beans to a WebSocket runtime
• using JSR-356 compliant runtimes or alternative engines
66www.springsource.org
Spring 4.0: Upcoming Enterprise Specs
 JMS 2.0
• delivery delay, JMS 2.0 createSession variants etc
 JTA 1.2
• javax.transaction.Transactional annotation
 JPA 2.1
• unsynchronized persistence contexts
 Bean Validation 1.1
• method parameter and return value constraints
 JSR-236 Concurrency Utilities
• EE-compliant TaskScheduler backend with trigger support
 JSR-107 JCache
• standard CacheManager backend, standard caching annotations
77www.springsource.org
Spring and Common Java SE Generations
 Spring 2.5 introduced Java 6 support
• JDK 1.4 – JDK 6
 Spring 3.0 raised the bar to Java 5+
• JDK 5 – JDK 6
 Spring 3.1/3.2: explicit Java 7 support
• JDK 5 – JDK 7
 Spring 4.0 introducing explicit Java 8 support now
• JDK 6 – JDK 8
88www.springsource.org
Spring and Common Java EE Generations
 Spring 2.5 completed Java EE 5 support
• J2EE 1.3 – Java EE 5
 Spring 3.0 introduced Java EE 6 support
• J2EE 1.4 – Java EE 6
 Spring 3.1/3.2: strong Servlet 3.0 focus
• J2EE 1.4 (deprecated) – Java EE 6
 Spring 4.0 introducing explicit Java EE 7 support now
• Java EE 5 (with JPA 2.0 feature pack) – Java EE 7
99www.springsource.org
The State of Java 8
 Delayed again...
• scheduled for GA in September 2013
• now just Developer Preview in September
• OpenJDK 8 GA as late as March 2014 (!)
 IDE support for Java 8 language features
• IntelliJ: available since IDEA 12, released in December 2012
• Eclipse: announced for June 2014 (!)
• Spring Tool Suite: trying to get some Eclipse-based support earlier
 Spring Framework 4.0 scheduled for GA in October 2013
• with best-effort Java 8 support on OpenJDK 8 Developer Preview
1010www.springsource.org
JSR-310 Date-Time
 Specialized date and time value types in java.time package
• replacing java.util.Date/Calendar, along the lines of the Joda-Time project
• Spring 4.0: annotation-driven date formatting
public class Customer {
// @DateTimeFormat(iso=ISO.DATE)
private LocalDate birthDate;
@DateTimeFormat(pattern="M/d/yy h:mm")
private LocalDateTime lastContact;
}
1111www.springsource.org
Lambda Conventions
 Many common Spring APIs are candidates for lambdas
• through naturally following the lambda interface conventions
• formerly "single abstract method" types, now "functional interfaces"
 JdbcTemplate
• ResultSetExtractor, RowCallbackHandler, RowMapper
 JmsTemplate
• MessageCreator, MessagePostProcessor, BrowserCallback
 TaskExecutor
• Runnable, Callable
1212www.springsource.org
JdbcTemplate jt = new JdbcTemplate(dataSource);
jt.query("SELECT name, age FROM person WHERE dep = ?",
ps -> { ps.setString(1, "Sales"); },
(rs, rowNum) -> new Person(rs.getString(1), rs.getInt(2)));
jt.query("SELECT name, age FROM person WHERE dep = ?",
ps -> {
ps.setString(1, "Sales");
},
(rs, rowNum) -> {
return new Person(rs.getString(1), rs.getInt(2));
});
Java 8 Lambdas with Spring's JdbcTemplate
1313www.springsource.org
public List<Person> getPersonList(String department) {
JdbcTemplate jt = new JdbcTemplate(this.dataSource);
return jt.query(
"SELECT name, age FROM person WHERE dep = ?",
ps -> {
ps.setString(1, "test");
},
this::mapPerson;
}
private Person mapPerson(ResultSet rs, int rowNum)
throws SQLException {
return new Person(rs.getString(1), rs.getInt(2));
}
Java 8 Method References with Spring's JdbcTemplate
1414www.springsource.org
Groovy Closures versus Lambdas
 Java 8 lambdas are quite restricted in their applicability
• always coerced into a specific target expression
• primarily a replacement for anonymous inner classes
 At the same time, lambdas are syntactically attractive
• concise (at least for Java terms)
• identifying overloaded methods through parameter name clause
 Groovy closures are a quite different beast
• a powerful first-class language and API construct
• mandatory "as“ clause for type coercion
1515www.springsource.org
Spring 4 and Groovy Closures
 Groovy closures to be equally attractive for Spring's callback APIs
• i.e. equally applicable to Java 8's functional interface conventions
• providing use cases for Groovy language enhancements
 Groovy 2.2: no "as“ clause necessary for unique type scenarios
• like with Java 8 lambdas, infer type from target context
• "as“ clause just to be used for overloaded methods
 Groovy 3.0: researching lambda/closure interoperability
• support for dedicated lambda syntax in Groovy?
• applying lambda expressions to Groovy Closure arguments?
1616www.springsource.org
Groovy-based Bean Definitions
 Essentially, Grails Bean Builder turning into a Spring feature
• revised bean builder API but same configuration format
• with Grails 3.0 building on it
beans {
dataSource(BasicDataSource) {
driverClassName = "org.h2.Driver"
url = "jdbc:h2:mem:grailsDB"
username = "sa"
password = ""
}
}
1717www.springsource.org
AOP Treatment for Groovy Classes
 Exclusion of internal Groovy interfaces from AOP proxying
• special detection of GroovyObject methods
• done in Grails already
• now in Spring's core AOP framework
 Applying aspects through Groovy AST transformations
• e.g. @Transactional processing
• Spring has separate "proxy" and "aspectj" modes already
• researching what a corresponding "groovy" mode could look like
• only makes sense for 100% Groovy-based application classes
1818www.springsource.org
Groovy as Language of Choice for Spring Apps
 The idea is simple:
• implementing a traditional Spring-style application architecture
• but with 100% Groovy instead of Java
 Spring's programming and configuration style with Groovy
• with the entire set of traditional Spring guidelines applying
• just replace an app's Java source files with Groovy source files
 Groovy 2's static compilation mode might be a good fit
• using @CompileStatic or @TypeChecked for semantics closer to Java
• potentially attractive to first-time Groovy adopters
1919www.springsource.org
Spring Framework 4.0 M1 & M2
 4.0 M1 (May 2013)
• general pruning and dependency upgrades (JDK 6+, JPA 2.0+, etc)
• initial Java 8 support based on OpenJDK 8 build 88
• JMS 2.0, JTA 1.2, JPA 2.1, Bean Validation 1.1, JSR-236 Concurrency
• initial WebSocket endpoint model
 4.0 M2 (July 2013)
• enhanced use of attributes on stereotype annotations
• generic type support for injection points
• Groovy-based bean definitions
• AOP treatment for Groovy classes
2020www.springsource.org
Q & A

Más contenido relacionado

La actualidad más candente

Managing user's data with Spring Session
Managing user's data with Spring SessionManaging user's data with Spring Session
Managing user's data with Spring SessionDavid Gómez García
 
RxJava from the trenches
RxJava from the trenchesRxJava from the trenches
RxJava from the trenchesPeter Hendriks
 
Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Matthew Barlocker
 
Kogito: cloud native business automation
Kogito: cloud native business automationKogito: cloud native business automation
Kogito: cloud native business automationMario Fusco
 
Data Migrations in the App Engine Datastore
Data Migrations in the App Engine DatastoreData Migrations in the App Engine Datastore
Data Migrations in the App Engine DatastoreRyan Morlok
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングscalaconfjp
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/HibernateSunghyouk Bae
 
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011Alexander Klimetschek
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play frameworkFelipe
 
High Performance Hibernate JavaZone 2016
High Performance Hibernate JavaZone 2016High Performance Hibernate JavaZone 2016
High Performance Hibernate JavaZone 2016Vlad Mihalcea
 
Play + scala + reactive mongo
Play + scala + reactive mongoPlay + scala + reactive mongo
Play + scala + reactive mongoMax Kremer
 
Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Oscar Renalias
 
High-Performance Hibernate Devoxx France 2016
High-Performance Hibernate Devoxx France 2016High-Performance Hibernate Devoxx France 2016
High-Performance Hibernate Devoxx France 2016Vlad Mihalcea
 
JPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsJPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsVlad Mihalcea
 
05 integrate redis
05 integrate redis05 integrate redis
05 integrate redisErhwen Kuo
 
Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Kotlin @ Coupang Backed - JetBrains Day seoul 2018Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Kotlin @ Coupang Backed - JetBrains Day seoul 2018Sunghyouk Bae
 
Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1Patrycja Wegrzynowicz
 

La actualidad más candente (20)

Managing user's data with Spring Session
Managing user's data with Spring SessionManaging user's data with Spring Session
Managing user's data with Spring Session
 
RxJava from the trenches
RxJava from the trenchesRxJava from the trenches
RxJava from the trenches
 
Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1
 
Dropwizard
DropwizardDropwizard
Dropwizard
 
Scala active record
Scala active recordScala active record
Scala active record
 
Kogito: cloud native business automation
Kogito: cloud native business automationKogito: cloud native business automation
Kogito: cloud native business automation
 
Data Migrations in the App Engine Datastore
Data Migrations in the App Engine DatastoreData Migrations in the App Engine Datastore
Data Migrations in the App Engine Datastore
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/Hibernate
 
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play framework
 
High Performance Hibernate JavaZone 2016
High Performance Hibernate JavaZone 2016High Performance Hibernate JavaZone 2016
High Performance Hibernate JavaZone 2016
 
Play + scala + reactive mongo
Play + scala + reactive mongoPlay + scala + reactive mongo
Play + scala + reactive mongo
 
Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0
 
High-Performance Hibernate Devoxx France 2016
High-Performance Hibernate Devoxx France 2016High-Performance Hibernate Devoxx France 2016
High-Performance Hibernate Devoxx France 2016
 
JPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsJPA and Hibernate Performance Tips
JPA and Hibernate Performance Tips
 
Spring Core
Spring CoreSpring Core
Spring Core
 
05 integrate redis
05 integrate redis05 integrate redis
05 integrate redis
 
Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Kotlin @ Coupang Backed - JetBrains Day seoul 2018Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Kotlin @ Coupang Backed - JetBrains Day seoul 2018
 
Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1
 

Similar a Spring 4-groovy

Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Sam Brannen
 
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Sam Brannen
 
Spring 4 on Java 8 by Juergen Hoeller
Spring 4 on Java 8 by Juergen HoellerSpring 4 on Java 8 by Juergen Hoeller
Spring 4 on Java 8 by Juergen HoellerZeroTurnaround
 
JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generation
JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next GenerationJAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generation
JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generationjazoon13
 
Spring5 New Features - Nov, 2017
Spring5 New Features - Nov, 2017Spring5 New Features - Nov, 2017
Spring5 New Features - Nov, 2017VMware Tanzu Korea
 
Creating applications with Grails, Angular JS and Spring Security
Creating applications with Grails, Angular JS and Spring SecurityCreating applications with Grails, Angular JS and Spring Security
Creating applications with Grails, Angular JS and Spring SecurityAlvaro Sanchez-Mariscal
 
Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Sam Brannen
 
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenSpring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenJAX London
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootJosué Neis
 
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012Sam Brannen
 
Spring Framework 4.1
Spring Framework 4.1Spring Framework 4.1
Spring Framework 4.1Sam Brannen
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Red Hat Developers
 
Java EE 8 Update
Java EE 8 UpdateJava EE 8 Update
Java EE 8 UpdateRyan Cuprak
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentationOleksii Usyk
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking TourJoshua Long
 

Similar a Spring 4-groovy (20)

Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1
 
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
 
Spring 4 on Java 8 by Juergen Hoeller
Spring 4 on Java 8 by Juergen HoellerSpring 4 on Java 8 by Juergen Hoeller
Spring 4 on Java 8 by Juergen Hoeller
 
JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generation
JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next GenerationJAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generation
JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generation
 
Get ready for spring 4
Get ready for spring 4Get ready for spring 4
Get ready for spring 4
 
Spring5 New Features - Nov, 2017
Spring5 New Features - Nov, 2017Spring5 New Features - Nov, 2017
Spring5 New Features - Nov, 2017
 
React inter3
React inter3React inter3
React inter3
 
Creating applications with Grails, Angular JS and Spring Security
Creating applications with Grails, Angular JS and Spring SecurityCreating applications with Grails, Angular JS and Spring Security
Creating applications with Grails, Angular JS and Spring Security
 
Java SE 8 & EE 7 Launch
Java SE 8 & EE 7 LaunchJava SE 8 & EE 7 Launch
Java SE 8 & EE 7 Launch
 
Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011
 
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenSpring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
 
JSF2
JSF2JSF2
JSF2
 
Spring Framework 4.1
Spring Framework 4.1Spring Framework 4.1
Spring Framework 4.1
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
 
Jsp
JspJsp
Jsp
 
Java EE 8 Update
Java EE 8 UpdateJava EE 8 Update
Java EE 8 Update
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 

Más de GR8Conf

DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your TeamGR8Conf
 
Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle GR8Conf
 
Mum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developerMum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developerGR8Conf
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with GroovyGR8Conf
 
Scraping with Geb
Scraping with GebScraping with Geb
Scraping with GebGR8Conf
 
How to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and AndroidHow to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and AndroidGR8Conf
 
Ratpack On the Docks
Ratpack On the DocksRatpack On the Docks
Ratpack On the DocksGR8Conf
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean CodeGR8Conf
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsGR8Conf
 
Performance tuning Grails applications
 Performance tuning Grails applications Performance tuning Grails applications
Performance tuning Grails applicationsGR8Conf
 
Ratpack and Grails 3
 Ratpack and Grails 3 Ratpack and Grails 3
Ratpack and Grails 3GR8Conf
 
Grails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloudGrails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloudGR8Conf
 
Functional testing your Grails app with GEB
Functional testing your Grails app with GEBFunctional testing your Grails app with GEB
Functional testing your Grails app with GEBGR8Conf
 
Deploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPCDeploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPCGR8Conf
 
The Grails introduction workshop
The Grails introduction workshopThe Grails introduction workshop
The Grails introduction workshopGR8Conf
 
Idiomatic spock
Idiomatic spockIdiomatic spock
Idiomatic spockGR8Conf
 
The Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedThe Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedGR8Conf
 
Groovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examplesGroovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examplesGR8Conf
 
Integration using Apache Camel and Groovy
Integration using Apache Camel and GroovyIntegration using Apache Camel and Groovy
Integration using Apache Camel and GroovyGR8Conf
 
CRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineCRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineGR8Conf
 

Más de GR8Conf (20)

DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your Team
 
Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle
 
Mum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developerMum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developer
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
 
Scraping with Geb
Scraping with GebScraping with Geb
Scraping with Geb
 
How to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and AndroidHow to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and Android
 
Ratpack On the Docks
Ratpack On the DocksRatpack On the Docks
Ratpack On the Docks
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature plugins
 
Performance tuning Grails applications
 Performance tuning Grails applications Performance tuning Grails applications
Performance tuning Grails applications
 
Ratpack and Grails 3
 Ratpack and Grails 3 Ratpack and Grails 3
Ratpack and Grails 3
 
Grails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloudGrails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloud
 
Functional testing your Grails app with GEB
Functional testing your Grails app with GEBFunctional testing your Grails app with GEB
Functional testing your Grails app with GEB
 
Deploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPCDeploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPC
 
The Grails introduction workshop
The Grails introduction workshopThe Grails introduction workshop
The Grails introduction workshop
 
Idiomatic spock
Idiomatic spockIdiomatic spock
Idiomatic spock
 
The Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedThe Groovy Ecosystem Revisited
The Groovy Ecosystem Revisited
 
Groovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examplesGroovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examples
 
Integration using Apache Camel and Groovy
Integration using Apache Camel and GroovyIntegration using Apache Camel and Groovy
Integration using Apache Camel and Groovy
 
CRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineCRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual Machine
 

Spring 4-groovy

  • 1. © 2012 SpringSource, A division of VMware. All rights reserved www.springsource.org Spring 4 Embracing Groovy – A Work in Progress Jürgen Höller, Principal Engineer, SpringSource
  • 2. 22www.springsource.org Review: Spring 3 Component Model Themes  Powerful annotated component model • stereotypes, configuration classes, composable annotations  Spring Expression Language • and its use in value injection  Comprehensive REST support • and other Spring @MVC additions  Support for async MVC processing • Spring MVC interacting with Servlet 3.0 async callbacks  Declarative validation and formatting • integration with JSR-303 Bean Validation  Declarative scheduling • trigger abstraction, cron support  Declarative caching
  • 3. 33www.springsource.org A Typical Annotated Component @Service public class MyBookAdminService implements BookAdminService { @Inject public MyBookAdminService(AccountRepository ar) { … } @Transactional public BookUpdate updateBook(Addendum addendum) { … } }
  • 4. 44www.springsource.org Configuration Classes @Configuration public class MyBookAdminConfig { @Bean public BookAdminService myBookAdminService() { MyBookAdminService service = new MyBookAdminService(); service.setDataSource(bookAdminDataSource()); return service; } @Bean public DataSource bookAdminDataSource() { … } }
  • 5. 55www.springsource.org Next Stop: Spring Framework 4.0  First-class support for Java 8 language and API features • lambda expressions • JSR-310 Date and Time • java.util.concurrency updates  First-class support for Groovy (in particular: Groovy 2) • Groovy-based bean definitions (a.k.a. Grails Bean Builder) • AOP treatment for Groovy classes  A WebSocket endpoint model along the lines of Spring MVC • deploying Spring-defined endpoint beans to a WebSocket runtime • using JSR-356 compliant runtimes or alternative engines
  • 6. 66www.springsource.org Spring 4.0: Upcoming Enterprise Specs  JMS 2.0 • delivery delay, JMS 2.0 createSession variants etc  JTA 1.2 • javax.transaction.Transactional annotation  JPA 2.1 • unsynchronized persistence contexts  Bean Validation 1.1 • method parameter and return value constraints  JSR-236 Concurrency Utilities • EE-compliant TaskScheduler backend with trigger support  JSR-107 JCache • standard CacheManager backend, standard caching annotations
  • 7. 77www.springsource.org Spring and Common Java SE Generations  Spring 2.5 introduced Java 6 support • JDK 1.4 – JDK 6  Spring 3.0 raised the bar to Java 5+ • JDK 5 – JDK 6  Spring 3.1/3.2: explicit Java 7 support • JDK 5 – JDK 7  Spring 4.0 introducing explicit Java 8 support now • JDK 6 – JDK 8
  • 8. 88www.springsource.org Spring and Common Java EE Generations  Spring 2.5 completed Java EE 5 support • J2EE 1.3 – Java EE 5  Spring 3.0 introduced Java EE 6 support • J2EE 1.4 – Java EE 6  Spring 3.1/3.2: strong Servlet 3.0 focus • J2EE 1.4 (deprecated) – Java EE 6  Spring 4.0 introducing explicit Java EE 7 support now • Java EE 5 (with JPA 2.0 feature pack) – Java EE 7
  • 9. 99www.springsource.org The State of Java 8  Delayed again... • scheduled for GA in September 2013 • now just Developer Preview in September • OpenJDK 8 GA as late as March 2014 (!)  IDE support for Java 8 language features • IntelliJ: available since IDEA 12, released in December 2012 • Eclipse: announced for June 2014 (!) • Spring Tool Suite: trying to get some Eclipse-based support earlier  Spring Framework 4.0 scheduled for GA in October 2013 • with best-effort Java 8 support on OpenJDK 8 Developer Preview
  • 10. 1010www.springsource.org JSR-310 Date-Time  Specialized date and time value types in java.time package • replacing java.util.Date/Calendar, along the lines of the Joda-Time project • Spring 4.0: annotation-driven date formatting public class Customer { // @DateTimeFormat(iso=ISO.DATE) private LocalDate birthDate; @DateTimeFormat(pattern="M/d/yy h:mm") private LocalDateTime lastContact; }
  • 11. 1111www.springsource.org Lambda Conventions  Many common Spring APIs are candidates for lambdas • through naturally following the lambda interface conventions • formerly "single abstract method" types, now "functional interfaces"  JdbcTemplate • ResultSetExtractor, RowCallbackHandler, RowMapper  JmsTemplate • MessageCreator, MessagePostProcessor, BrowserCallback  TaskExecutor • Runnable, Callable
  • 12. 1212www.springsource.org JdbcTemplate jt = new JdbcTemplate(dataSource); jt.query("SELECT name, age FROM person WHERE dep = ?", ps -> { ps.setString(1, "Sales"); }, (rs, rowNum) -> new Person(rs.getString(1), rs.getInt(2))); jt.query("SELECT name, age FROM person WHERE dep = ?", ps -> { ps.setString(1, "Sales"); }, (rs, rowNum) -> { return new Person(rs.getString(1), rs.getInt(2)); }); Java 8 Lambdas with Spring's JdbcTemplate
  • 13. 1313www.springsource.org public List<Person> getPersonList(String department) { JdbcTemplate jt = new JdbcTemplate(this.dataSource); return jt.query( "SELECT name, age FROM person WHERE dep = ?", ps -> { ps.setString(1, "test"); }, this::mapPerson; } private Person mapPerson(ResultSet rs, int rowNum) throws SQLException { return new Person(rs.getString(1), rs.getInt(2)); } Java 8 Method References with Spring's JdbcTemplate
  • 14. 1414www.springsource.org Groovy Closures versus Lambdas  Java 8 lambdas are quite restricted in their applicability • always coerced into a specific target expression • primarily a replacement for anonymous inner classes  At the same time, lambdas are syntactically attractive • concise (at least for Java terms) • identifying overloaded methods through parameter name clause  Groovy closures are a quite different beast • a powerful first-class language and API construct • mandatory "as“ clause for type coercion
  • 15. 1515www.springsource.org Spring 4 and Groovy Closures  Groovy closures to be equally attractive for Spring's callback APIs • i.e. equally applicable to Java 8's functional interface conventions • providing use cases for Groovy language enhancements  Groovy 2.2: no "as“ clause necessary for unique type scenarios • like with Java 8 lambdas, infer type from target context • "as“ clause just to be used for overloaded methods  Groovy 3.0: researching lambda/closure interoperability • support for dedicated lambda syntax in Groovy? • applying lambda expressions to Groovy Closure arguments?
  • 16. 1616www.springsource.org Groovy-based Bean Definitions  Essentially, Grails Bean Builder turning into a Spring feature • revised bean builder API but same configuration format • with Grails 3.0 building on it beans { dataSource(BasicDataSource) { driverClassName = "org.h2.Driver" url = "jdbc:h2:mem:grailsDB" username = "sa" password = "" } }
  • 17. 1717www.springsource.org AOP Treatment for Groovy Classes  Exclusion of internal Groovy interfaces from AOP proxying • special detection of GroovyObject methods • done in Grails already • now in Spring's core AOP framework  Applying aspects through Groovy AST transformations • e.g. @Transactional processing • Spring has separate "proxy" and "aspectj" modes already • researching what a corresponding "groovy" mode could look like • only makes sense for 100% Groovy-based application classes
  • 18. 1818www.springsource.org Groovy as Language of Choice for Spring Apps  The idea is simple: • implementing a traditional Spring-style application architecture • but with 100% Groovy instead of Java  Spring's programming and configuration style with Groovy • with the entire set of traditional Spring guidelines applying • just replace an app's Java source files with Groovy source files  Groovy 2's static compilation mode might be a good fit • using @CompileStatic or @TypeChecked for semantics closer to Java • potentially attractive to first-time Groovy adopters
  • 19. 1919www.springsource.org Spring Framework 4.0 M1 & M2  4.0 M1 (May 2013) • general pruning and dependency upgrades (JDK 6+, JPA 2.0+, etc) • initial Java 8 support based on OpenJDK 8 build 88 • JMS 2.0, JTA 1.2, JPA 2.1, Bean Validation 1.1, JSR-236 Concurrency • initial WebSocket endpoint model  4.0 M2 (July 2013) • enhanced use of attributes on stereotype annotations • generic type support for injection points • Groovy-based bean definitions • AOP treatment for Groovy classes