Upload
spring-io
View
328
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Speaker: Kenneth Kousen The Spring framework has always had a friendly relationship with dynamic languages. In this presentation, we'll look at all the ways you can add Groovy to Spring to make development easier, ranging from simplifying your configuration files to deploying refreshable beans to using Spock tests in the Spring test context and more. Groovy works comfortably with existing Java infrastructure, and Spring has special capabilities designed specifically for scripting languages. The combination is very powerful and is an easy way to take advantage of Groovy code simplification.
Citation preview
Making Spring Groovy
The Spring Framework
Dependency injection
Huge library of “beans”
Open source
The Swiss Army Chainsaw of Frameworks
Hello, Spring!
Not much point
Replaces simple Java with complex Javaand configuration metadata
Need an app with some services...
Managing Accounts
Managing Accounts
Spring manages:Account serviceAccount repositoryTransactionsInjected dependencies
Managing Accounts
Spring provides:jdbcTemplateEmbedded database for testing
Testing
Spring test contextCaches application contextRolls back transactions after each testGreat for testing DAO layers
Spring and Groovy
1. POGOs are Spring beans toobytecodes are bytecodes
Account Demo
Classes:Account.groovy → POGOAccountDAO.java → integrationJdbcAccountDAO.groovy
AccountService.java
Spock tests
Spring and Groovy
2. Refreshable beansUse lang: namespaceDeploy Groovy source codeCan update running system
Mortgage Evaluator
Mortgage Evaluator Demo
Classes:MortgageApplication.groovy
Evaluator.java
JavaEvaluator.java
GroovyEvaluator.groovy → refreshable
Spock tests
Spring and Groovy
3. AOPImplement aspects in Groovy
Tracking Properties
Tracking Properties
Files:POJO.java
ChangeLogger.java
UpdateReporter.groovy
applicationContext.xml
JUnit tests
Spring and Groovy
4. Inline scripted beansBean definitions in config filesA feature looking for an application
Inline scripted beans
Files:Same as AOP, but
bean def in applicationContext.xml
Spring and Groovy
5. BeanBuilder class from Grails(projected to be in Spring 4.0)
Builder syntax for bean config
BeanBuilder
Files:BeanBuilderTests.groovy
(from Grails distribution)
Spring Boot
6. Spring Boot
Sample application (Java) athttp://spring.io/guides/gs/spring-boot/
I added a Groovy demo as well
Conclusions
POGOs are Groovy beans
Unique to dynamic languages in Spring:Refreshable beansInline scripted beansBeanBuilder configuration class
Spring boot looks cool