Transcript
Page 1: Making Spring Groovy

Making Spring Groovy

Page 3: Making Spring Groovy
Page 4: Making Spring Groovy

The Spring Framework

Dependency injection

Huge library of “beans”

Open source

The Swiss Army Chainsaw of Frameworks

Page 5: Making Spring Groovy

Hello, Spring!

Not much point

Replaces simple Java with complex Javaand configuration metadata

Need an app with some services...

Page 6: Making Spring Groovy

Managing Accounts

Page 7: Making Spring Groovy

Managing Accounts

Spring manages:Account serviceAccount repositoryTransactionsInjected dependencies

Page 8: Making Spring Groovy

Managing Accounts

Spring provides:jdbcTemplateEmbedded database for testing

Page 9: Making Spring Groovy

Testing

Spring test contextCaches application contextRolls back transactions after each testGreat for testing DAO layers

Page 10: Making Spring Groovy

Spring and Groovy

1. POGOs are Spring beans toobytecodes are bytecodes

Page 11: Making Spring Groovy

Account Demo

Classes:Account.groovy → POGOAccountDAO.java → integrationJdbcAccountDAO.groovy

AccountService.java

Spock tests

Page 12: Making Spring Groovy

Spring and Groovy

2. Refreshable beansUse lang: namespaceDeploy Groovy source codeCan update running system

Page 13: Making Spring Groovy

Mortgage Evaluator

Page 14: Making Spring Groovy

Mortgage Evaluator Demo

Classes:MortgageApplication.groovy

Evaluator.java

JavaEvaluator.java

GroovyEvaluator.groovy → refreshable

Spock tests

Page 15: Making Spring Groovy

Spring and Groovy

3. AOPImplement aspects in Groovy

Page 16: Making Spring Groovy

Tracking Properties

Page 17: Making Spring Groovy

Tracking Properties

Files:POJO.java

ChangeLogger.java

UpdateReporter.groovy

applicationContext.xml

JUnit tests

Page 18: Making Spring Groovy

Spring and Groovy

4. Inline scripted beansBean definitions in config filesA feature looking for an application

Page 19: Making Spring Groovy

Inline scripted beans

Files:Same as AOP, but

bean def in applicationContext.xml

Page 20: Making Spring Groovy

Spring and Groovy

5. BeanBuilder class from Grails(projected to be in Spring 4.0)

Builder syntax for bean config

Page 21: Making Spring Groovy

BeanBuilder

Files:BeanBuilderTests.groovy

(from Grails distribution)

Page 22: Making Spring Groovy

Spring Boot

6. Spring Boot

Sample application (Java) athttp://spring.io/guides/gs/spring-boot/

I added a Groovy demo as well

Page 23: Making Spring Groovy

Conclusions

POGOs are Groovy beans

Unique to dynamic languages in Spring:Refreshable beansInline scripted beansBeanBuilder configuration class

Spring boot looks cool


Top Related