Download - Making Spring Groovy
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