Zero Effort Spring
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Zero Effort Spring

on

  • 1,359 views

Speakers: Dave Syer and Phil Webb ...

Speakers: Dave Syer and Phil Webb
Are you an impatient programmer who wishes the keyboard could keep up with you? If you've ever wished Java and Spring could do more to keep up, then this is the place to be. We present Spring Boot, a toolkit and runtime platform that will get you up and running with Spring-powered, production-grade applications and services faster than you believed possible. The goals are:
Radically faster and widely accessible getting started experience for Spring development
Be opinionated out of the box, but get out of the way quickly as requirements start to diverge from the defaults
Provide a range of non-functional features that are common to large classes of projects (e.g. embedded servers, security, metrics, health checks, externalized configuration)
First class support for REST-ful services, modern web applications, batch jobs, and enterprise integration
Applications that adapt their behavior or configuration to their environment
Optionally use Groovy features like DSLs and AST transformations to accelerate the implementation of basic business requirements We illustrate how these goals can be achieved through a series of demonstrations, and in-depth reviews of the design principles and codebase of new features in Spring Framework 4.0 and in the wider Spring Ecosystem .

Statistics

Views

Total Views
1,359
Views on SlideShare
1,359
Embed Views
0

Actions

Likes
3
Downloads
9
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Zero Effort Spring Presentation Transcript

  • 1. 1 of 37 Spring Boot Dave Syer, Phil Webb, 2013 Twitter: @david_syer, @phillip_webb Email: [dsyer, pwebb]@gopivotal.com (Introduction to Spring Boot) 03/09/13 14:50
  • 2. 2 of 37 03/09/13 14:50
  • 3. 3 of 37 Agenda Quick overview of goals and high level features Getting started demo Behind the scenes of @EnableAutoConfiguration Adding new features to Spring Boot 03/09/13 14:50
  • 4. 4 of 37 Introduction Spring Boot: Focuses attention at a single point (as opposed to large collection of spring-* projects) A tool for getting started very quickly with Spring Common non-functional requirements for a "real" application Exposes a lot of useful features by default Gets out of the way quickly if you want to change defaults An opportunity for Spring to be opinionated 03/09/13 14:50
  • 5. 5 of 37 Focus Attention 03/09/13 14:50
  • 6. 6 of 37 Spring Boot Goals Provide a radically faster and widely accessible getting started experience Be opinionated out of the box, but get out of the way quickly as requirements start to diverge from the defaults Provide a range of non-functional features that are common to large classes of projects (e.g. embedded servers, security, metrics, health checks, externalized configuration) Absolutely no code generation and no requirement for XML configuration 03/09/13 14:50
  • 7. 7 of 37 Getting Started Really Quickly app.groovy: @Controller class Application { @RequestMapping('/') @ResponseBody String home() { 'Hello World!' } } then $ spring run app.groovy 03/09/13 14:50
  • 8. 8 of 37 Getting Started DEMO 03/09/13 14:50
  • 9. 9 of 37 Getting Started In Java Application.java: ... @Controller @EnableAutoConfiguration public class Application { @RequestMapping("/") @ResponseBody public String home() { "Hello World!"; } public static main(String[] args) { SpringApplication.run(Application.class, args); } } 03/09/13 14:50
  • 10. 10 of 37 Getting Started In Java ...then $ mvn package $ java -jar target/*.jar (or use gradle equivalents) 03/09/13 14:50
  • 11. 11 of 37 Getting Started DEMO 03/09/13 14:50
  • 12. 12 of 37 What Just Happened? SpringApplication: convenient way to write a main() method that loads a Spring context @EnableAutoConfiguration: optional annotation that adds stuff to your context, including... EmbeddedServletContainerFactory: added to your context if a server is available on the classpath CommandLineRunner: a hook to run application-specific code after the context is created JarLauncher was added to the JAR file 03/09/13 14:50
  • 13. 13 of 37 Spring Boot Modules Spring Boot - main library supporting the other parts of Spring Boot Spring Boot Autoconfigure - single @EnableAutoConfiguration annotation creates a whole Spring context Spring Boot Starters - a set of convenient dependency descriptors that you can include in your application. Spring Boot CLI - compiles and runs Groovy source as a Spring application Spring Boot Actuator - comman non-functional features that make an app instantly deployable and supportable in production Spring Boot Tools - for building and executing self-contained JAR and WAR archives Spring Boot Samples - a wide range of sample apps 03/09/13 14:50
  • 14. 14 of 37 Spring Boot Module Relations 03/09/13 14:50
  • 15. 15 of 37 Binding to Command Line Arguments SpringApplication binds its own bean properties to command line arguments, and then adds them to the Spring Environment, e.g. $ java -jar target/*.jar --server.port=9000 03/09/13 14:50
  • 16. 16 of 37 Externalizing Configuration to Properties Just put application.properties in your classpath, e.g. application.properties server.port: 9000 03/09/13 14:50
  • 17. 17 of 37 Using YAML Just put application.yml in your classpath application.yml server: port: 9000 Both properties and YAML add entries with period-separated paths to the Spring Environment. 03/09/13 14:50
  • 18. 18 of 37 Binding External Configuration To Beans MineProperties.java @ConfigurationProperties(prefix="mine") public class MinePoperties { private Resource location; private boolean skip = true; // ... getters and setters } application.properties mine.location: classpath:mine.xml mine.skip: false 03/09/13 14:50
  • 19. 19 of 37 Customizing Configuration Location Set spring.config.name - default application, can be commaseparated list spring.config.location - a Resource path, overrides name e.g. $ java -jar target/*.jar --spring.config.name=sagan 03/09/13 14:50
  • 20. 20 of 37 Spring Profiles Activate external configuration with a Spring profile file name convention e.g. applicationdevelopment.properties or nested documents: application.yml defaults: etc... --spring: profiles: development,postgresql other: stuff: more stuff... Set the default spring profile in external configuration, e.g: application.properties spring.profiles.active: default,postgresql 03/09/13 14:50
  • 21. 21 of 37 Adding some Autoconfigured Behaviour Extend the demo and see what we can get by just modifying the classpath, e.g. Add an in memory database Add a Tomcat connection pool 03/09/13 14:50
  • 22. 22 of 37 Adding A UI with Thymeleaf Add Thymeleaf to the classpath and see it render a view Spring Boot Autoconfigure has added all the boilerplate stuff Common configuration options via spring.thymeleaf.*, e.g. spring.thymeleaf.prefix:classpath:/templates/ (location of templates) spring.tjymeleaf.cache:true (set to false to reload templates when changed) Extend and override: add Thymeleaf IDialect beans add thymeleafViewResolver add SpringTemplateEngine add defaultTemplateResolver 03/09/13 14:50
  • 23. 23 of 37 Currently Available Autoconfigured Behaviour Embedded servlet container (Tomcat or Jetty) DataSource and JdbcTemplate JPA Spring Data JPA (scan for repositories) Thymeleaf Batch processing Reactor for events and async processing Actuator features (Security, Audit, Metrics, Trace) 03/09/13 14:50
  • 24. 24 of 37 Building a WAR We like launchable JARs, but you can still use WAR format if you prefer. Spring Boot Tools take care of repackaging a WAR to make it executable. If you want a WAR to be deployable (in a "normal" container), then you need to use SprinBootServletInitializer instead of or as well as SpringApplication. 03/09/13 14:50
  • 25. 25 of 37 The Actuator Adds common non-functional features to your application and exposes MVC endpoints to interact with them. Security Secure endpoints: /metrics, /health, /trace, /dump, /shutdown, /beans Audit /info If embedded in a web app or web service can use the same port or a different one (and a different network interface). 03/09/13 14:50
  • 26. 26 of 37 Adding Security Use the Actuator Add Spring Security to classpath 03/09/13 14:50
  • 27. 27 of 37 Logging Spring Boot provides default configuration files for 3 common logging frameworks: logback, log4j and java.util.logging Starters (and Samples) use logback External configuration and classpath influence runtime behaviour LoggingApplicationContextInitializer sets it all up 03/09/13 14:50
  • 28. 28 of 37 Customizing the ApplicationContext Creation Add external configuration (System properties, OS env vars, config file, command line arguments) Add ApplicationContextInitializer implementations and enable in application.properties 03/09/13 14:50
  • 29. 29 of 37 Customizing the @EnableAutoConfiguration Behaviour Add JAR with META-INF/spring.factories entry for EnableAutoConfiguration All entries from classpath merged and added to context 03/09/13 14:50
  • 30. 30 of 37 Customizing the CLI Uses standard Java META-INF/services scanning CompilerAutoConfiguration: add dependencies and imports CommandFactory: add commands via a custom CommandFactory in META-INF/services E.g. can add script commands (written in Groovy) $ spring foo ... Looks for foo.groovy in ${SPRING_HOME}/bin and ${SPRING_HOME}/ext by default 03/09/13 14:50
  • 31. 31 of 37 Customizing Servlet Container Properties Some common features exposed with external configuration, e.g. server.port (see ServerProperties bean) Add bean of type EmbeddedServletContainerCustomizer - all instances get a callback Add bean of type EmbeddedServletContainerFactory (replacing auto-configured one) 03/09/13 14:50
  • 32. 32 of 37 Spring Boot Loader Motivation: existing solutions for executable JAR are not very robust; executable WAR is very tricky to create. Response: JarLauncher and WarLauncher with specialized ClassLoader implementations that can find resources in nested JARs (e.g. lib/*.jar or WEB-INF/lib/*.jar) 03/09/13 14:50
  • 33. 33 of 37 Maven and Gradle Tooling Create an executable archive (JAR or WAR) Maven plugin (using spring-boot-starter-parent): ${project.groupId} spring-boot-maven-plugin $ mvn package Gradle plugin: apply plugin: 'spring-boot' $ gradle repackage 03/09/13 14:50
  • 34. 34 of 37 Testing with Spring Test (MVC) SpringApplication is an opinionated creator of an ApplicationContext, but most of the behaviour is encapsulated in ApplicationContextInitializer implementations. To reproduce the behaviour of you app in an integration test it is useful to duplicate those features you can use the corresponding initializers. Example if you have externalized configuration: 03/09/13 14:50
  • 35. 35 of 37 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = IntegrationTestsConfiguration.class, initializers = ConfigFileApplicationContextInitializer.class) public class IntegrationTests { // Normal Spring Test stuff } 03/09/13 14:50
  • 36. 36 of 37 Links https://github.com/SpringSource/spring-boot Spring Boot on Github https://projects.spring.io/spring-boot Documentation http://spring.io/blog http://dsyer.com/decks/spring-boot-intro.md.html Twitter: @david_syer Email: dsyer@vmware.com 03/09/13 14:50
  • 37. 37 of 37 Spring Boot Intro - END 03/09/13 14:50