spring boot 3g
TRANSCRIPT
SpringBoot+ Groovy, Gorm, Gradle
Presented by: Vasu Srinivasan, Texas NIC UsaFor: Austin Groovy-Grails User Group (AGGUG), 2014-06-12
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
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
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
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
opinionated frameworks frameworks that have
strong opinions about themselves
framework by developers who have strong opinions about what goes in
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 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)
using:groovy traditional Spring apps are mostly in Java, but Groovy is a
smoother, richer language
Groovy enriches Spring Boot in many ways
using:boot-with-groovyGroovy in Boot How?
Using spring-cli, run Groovy scripts
spring run app.groovybut 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 beansJust 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/*.tplpractical 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 Grailscompile("org.grails:gorm-hibernate4-spring-boot:1.0.0.GA")Annotate domain class with @Entity
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
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/
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
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
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
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
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
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?
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!)
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
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
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?
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?
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/html
single/
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
Thank you!Austin Groovy/Grails User Group
ReachForce, AustinTexas NIC, Austin (Sponsor)
SpringBoot, Groovy, Grails, Gradle team!