SpringBoot
+ Groovy, Gorm, Gradle
Presented by: Vasu Srinivasan, Texas NIC Usa
For: Austin Groovy-Grails User Group (AGGUG...
about:me
 Vasu Srinivasan
 Sr Tech Consultant at Texas NIC, USA
 Twitter: @vasya10
 Blog: http://vasya10.wordpress.com...
about:Texas NIC, USA
 NIC is in 29 states, specializing in e-government
 scrum teams
 Grails, SpringBoot, Spring, Oracl...
why-not:spring
 scalability has become a key issue for enterprise applications
 stateless services provide better scalab...
why:spring-boot
 xml as a configuration – an idea’s time has passed (long ago)
 obviously verbose, bloated and error-pro...
opinionated frameworks
 frameworks that have
strong opinions about
themselves
 framework by developers
who have strong o...
why:boot
 spring booted xml out:
so “SpringBoot”
 of course, that’s the unofficial version of the story
about:spring-boot
 container project for creating new Spring based applications
 embedded servlet container: Tomcat or J...
using:groovy
 traditional Spring apps are mostly in Java, but Groovy is a
smoother, richer language
 Groovy enriches Spr...
using:boot-with-groovy
Groovy in Boot How?
Using spring-cli, run Groovy
scripts
spring run app.groovy
but would anyone do ...
using:boot-with-groovy highlights
 Some immediate advantages using Groovy
 Practical and time-saving annotations
 @ToSt...
spring-boot:demo1
 Starter Project – Spring Initializer
 start.spring.io
 add required poms, select “Gradle Project”
 ...
spring-boot:demo1
 Actuators
 /beans
 /metrics
 /health
 /shutdown
 /trace
 /dump
 Auto-configures database for HS...
spring-boot:demo2
 Star Catalog
 Simple Rest Service (Get and Post)
 AngularJS as client
 Batch Processing
 Groovy Be...
spring-boot:good-bad-and-ugly
Good, Baffling and the Unexpected
spring-boot:good
 traditional Spring MVC (xml) developers will
surely see advantages in reduced / manual
configurations
...
spring-boot:baffling
 Multiple ways to setup properties
 application.properties, application.yml
 Decide on early. Go Y...
spring-boot:baffling
 Too many @configuration related annotations
 @AutoConfigure, @Configuration, @EnableConfiguration,...
spring-boot:baffling
 what are my views?
 jsp (anyone still using this???!)
 thymeleaf (good and clean library)
 groov...
spring-boot:unexpected
 Grails Domain objects cannot be converted to
Json directly
 needs a custom mapper in between
 N...
spring-boot:ide tricks (IntelliJ)
 run the main application directly, not via gradle bootRun
 For debugging add VM optio...
spring-boot:nice-to-have
 faster creation of project templates, instead of browser
 groovy configuration support (like ....
spring-boot:should we?
 already a heavily invested traditional Spring shop?
 desperately want to scale your apps now?
 ...
Links, References, Acknowledgements
 Spring Initializr - http://start.spring.io
 http://www.infoq.com/articles/microserv...
Thank you!
Austin Groovy/Grails User Group
ReachForce, Austin
Texas NIC, Austin (Sponsor)
SpringBoot, Groovy, Grails, Grad...
Spring boot 3g
Upcoming SlideShare
Loading in …5
×

Spring boot 3g

2,255 views

Published on

Published in: Technology
1 Comment
6 Likes
Statistics
Notes
No Downloads
Views
Total views
2,255
On SlideShare
0
From Embeds
0
Number of Embeds
79
Actions
Shares
0
Downloads
44
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide

Spring boot 3g

  1. 1. SpringBoot + Groovy, Gorm, Gradle Presented by: Vasu Srinivasan, Texas NIC Usa For: Austin Groovy-Grails User Group (AGGUG), 2014-06-12
  2. 2. about:me  Vasu Srinivasan  Sr Tech Consultant at Texas NIC, USA  Twitter: @vasya10  Blog: http://vasya10.wordpress.com  Slides: http://www.slideshare.net/vasya10/  Videos:  Battle of Programming Languages -https://www.youtube.com/watch?v=dKftGfU0giA  Along with Eric Kelm (@asoftwareguy, asoftwareguy.com)  Current interests  Grails/Groovy, AngularJS, SharePoint, Java, MongoDB, NodeJs
  3. 3. about:Texas NIC, USA  NIC is in 29 states, specializing in e-government  scrum teams  Grails, SpringBoot, Spring, Oracle SOA, SharePoint, .Net stack  major applications  www.texas.gov  licensing applications  driver license renewals and reinstatements  concealed handgun  occupational and renewal licenses  birth and death certificates  vehicle inspections  texas department of criminal justice - Inmates App  and many many more!  our work benefits and impacts Texans directly
  4. 4. why-not:spring  scalability has become a key issue for enterprise applications  stateless services provide better scalability  stand-alone monolithic servlet container and cluster management has in some cases become a specialized job (WebSphere anyone?)  a simple http server is sufficient for many small-to-medium applications  how application is deployed, forces how to write code  conceptually this will not change, but a certain level of freedom goes a long way in maintenance and extensibility  ramp up time to create a simple starter app is pretty high  many modern web frameworks have < 5 minutes to download the libraries and create a simple application
  5. 5. why:spring-boot  xml as a configuration – an idea’s time has passed (long ago)  obviously verbose, bloated and error-prone  many post-Spring web frameworks use zero xml for configuration  Rails, Grails, Play, Wicket, etc.  ramp up time is a very important criteria  Play? play install run !  Or Grails? grails create-app !  opinionated frameworks are becoming fashionable, again?  Spring had to do something to compete with fast evolving frameworks such as DropWizard, Ratpack, Sinatra, Scalatra with the concept of “micro- services architecture” (MSA)  With its vast supporting frameworks/libraries including a solid DI mechanism, it needed a simple way to tie them all
  6. 6. opinionated frameworks  frameworks that have strong opinions about themselves  framework by developers who have strong opinions about what goes in
  7. 7. why:boot  spring booted xml out: so “SpringBoot”  of course, that’s the unofficial version of the story
  8. 8. about:spring-boot  container project for creating new Spring based applications  embedded servlet container: Tomcat or Jetty  starter POMs for many libraries (web, jdbc, log, data etc)  auto configurations  actuators (health, metrics, beans, shutdown, ssh, etc.)  xml, java annotated, groovy bean configurations  xml configuration not mandatory anymore  supports many dbs via spring-data  helps blend web and non-web (eg. batch) functionality  supports many views  jsp (limited), thymeleaf, and groovy template engine too! (1.1.0)
  9. 9. using:groovy  traditional Spring apps are mostly in Java, but Groovy is a smoother, richer language  Groovy enriches Spring Boot in many ways
  10. 10. using:boot-with-groovy Groovy in Boot How? Using spring-cli, run Groovy scripts spring run app.groovy but would anyone do this in prod? not sure. Use groovy as the language, instead of Java, the language apply plugin: ‘groovy’ compile (“org.codehaus.groovy:groovy:$groovyVersion) Use Groovy Bean configuration instead of xml Boot’s GroovyBeanDefinitionReader wires the beans Just like Grails resources.groovy Use Groovy Template Engine since Boot 1.1.0 and Groovy 2.3.2 easy to create html via markup template. templates in src/main/resources/templates/*.tpl practical in cases where html is an overkill (email templates, display history data etc.) compile "org.codehaus.groovy:groovy- templates:${groovyVersion}" Using Gorm Spin-off from Grails compile("org.grails:gorm-hibernate4-spring- boot:1.0.0.GA")
  11. 11. using:boot-with-groovy highlights  Some immediate advantages using Groovy  Practical and time-saving annotations  @ToString, @Log, @EqualsAndHashCode  Faster Json conversions (with Groovy 2.3)  Null-safe operations  Groovy Strings  Test using Spock  Many classes can apply @CompileStatic and be as fast as Java
  12. 12. spring-boot:demo1  Starter Project – Spring Initializer  start.spring.io  add required poms, select “Gradle Project”  unzip the downloaded file  Add default gradle wrapper artifacts  Fix Application.groovy  Add logback.groovy  gradlew clean bootRun  In Mac/Linux use gvm, lazybones  http://www.nautsch.net/2014/04/15/spring-boot-running-in-2-min/
  13. 13. spring-boot:demo1  Actuators  /beans  /metrics  /health  /shutdown  /trace  /dump  Auto-configures database for HSQL DB  Auto-configures a bunch of other beans  Adds a default Tomcat servlet container to run on port 8080
  14. 14. spring-boot:demo2  Star Catalog  Simple Rest Service (Get and Post)  AngularJS as client  Batch Processing  Groovy Bean Configuration  Groovy Template Engine as View layer
  15. 15. spring-boot:good-bad-and-ugly Good, Baffling and the Unexpected
  16. 16. spring-boot:good  traditional Spring MVC (xml) developers will surely see advantages in reduced / manual configurations  rest made easy  deployment made easy  auto-configurations largely reduce initial dependency management  java annotated configurations provide type- safety check  well modularized, instead of a “kitchen-sink” approach  gradle support is awesome
  17. 17. spring-boot:baffling  Multiple ways to setup properties  application.properties, application.yml  Decide on early. Go YAML.  Too many logging frameworks are included in classpath  Strongly recommend to use logback as standard, logback.groovy works fine  No out of the box support for profiles  Grails by default provides environment blocks in the configurations, making it super easy to configure for different environments  In SpringBoot, some handcraft is required to create profiles (development section in yml or application-development.properties)  Power of grailsApplication.config will be missed
  18. 18. spring-boot:baffling  Too many @configuration related annotations  @AutoConfigure, @Configuration, @EnableConfiguration, @EnableConfigurationProperties, @ConfigurationProperties, @PropertySource, @Value  Annotations cannot be intuitively applied, reference documentation is the main guide  Too many annotations in general – sometimes I wonder what is my business logic (@Bean, @PostConstruct, @ComponentScan)  once you get past the auto-configuration magic, overriding the configurations takes a bit of discovery time  what to wire?  what properties are required?
  19. 19. spring-boot:baffling  what are my views?  jsp (anyone still using this???!)  thymeleaf (good and clean library)  groovy template engine  gsp (stand-alone spin-off from grails)  where are my views?  recommended path is src/main/resources/static  too deep in the IDE view  IDE settings can mistake static to be a java package, resulting in undesirable refactors (rename for eg)  or use webjars for javascript jars  UI Team may like to use bower like js dependency package tools  are webjars always current?  need build customizations if using bower, sass  no out of box support (yet) or grails plugin like asset-pipeline (opportunity to develop!)
  20. 20. spring-boot:unexpected  Grails Domain objects cannot be converted to Json directly  needs a custom mapper in between  Not all xml configuration enhancements translate to Groovy Bean DSL  eg. <ctx:annotation-config/> works  but not <batch:/>  Broke in Spring Boot 1.1.x  Gorm @Transactional is broke – throws Proxy error  Gorm methods are not available at startup time (Bootstrap/InitializingBean)  substitute with a manual restful controller initiated call to initialize records
  21. 21. spring-boot:ide tricks (IntelliJ)  run the main application directly, not via gradle bootRun  For debugging add VM option  -javaagent:/path/springloaded-1.2.0.RELEASE.jar -noverify  then, debug the main application  sometimes port is not released (Windows)  netstat –o –a –n | findstr “8080”  stop-process $id  Associate groovy template .tpl files with “Groovy” for auto-formatting
  22. 22. spring-boot:nice-to-have  faster creation of project templates, instead of browser  groovy configuration support (like .properties, .yaml)  richer runtime evaluations, environment block support  out of the box support for common active profiles  expose entities as Rest Entities for prototypes (like Grails @Resource)  tooling support for Groovy Bean DSL and GTE  Well, perhaps they are already in the making … ?  grails-boot?
  23. 23. spring-boot:should we?  already a heavily invested traditional Spring shop?  desperately want to scale your apps now?  xml configurations giving you nightmares or headaches?  want a better deployment strategy?  want to hop on the micro-services wagon?  can’t wait for grails-boot?  all of the above?  any one of the above?
  24. 24. Links, References, Acknowledgements  Spring Initializr - http://start.spring.io  http://www.infoq.com/articles/microservices-intro  http://docs.spring.io/spring-boot/docs/current- SNAPSHOT/reference/htmlsingle/  Demo Application (StarCatalog) - https://github.com/vasya10/spring-boot- batch-sample  Testing SpringBoot with Spock - http://fbflex.wordpress.com/2013/09/18/testing-spring-boot-applications- with-spock/  Google Image search for cute Puss in Boots images  Disney / Dreamworks for Puss in Boots images  Images are used in good intention only to illustrate context of topic
  25. 25. Thank you! Austin Groovy/Grails User Group ReachForce, Austin Texas NIC, Austin (Sponsor) SpringBoot, Groovy, Grails, Gradle team!

×