Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Spring Boot

143 views

Published on

Introduction to Spring Boot and how to build microservices with the framework.

Published in: Software
  • Be the first to comment

Spring Boot

  1. 1. Spring Boot Applications. Simply.
  2. 2. Jaran Flaath • Senior consultant at Kodehuset • 12 years of professional software development experience • Frequent speaker • Previous leader of javaBin Sørlandet and VP of javaBin • When not coding: Building LEGO and driving R/C cars • http://twitter.com/jaranflaath
  3. 3. What is Spring?
  4. 4. What is Spring? Modular application framework assisting with almost any aspect of modern application development
  5. 5. What is Spring? Modular application framework assisting with almost any aspect of modern application development
  6. 6. What is Spring Boot?
  7. 7. Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". What is Spring Boot?
  8. 8. Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". What is Spring Boot?
  9. 9. FEATURES
  10. 10. • Create stand-alone Spring applications
  11. 11. • Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
  12. 12. • Provide opinionated 'starter' POMs to simplify your Maven or Gradle configuration
  13. 13. • Automatically configure Spring whenever possible
  14. 14. • Provide production-ready features such as metrics, health checks and externalised configuration
  15. 15. • No code generation or XML configuration
  16. 16. Maven and Gradle support via starter-artifacts • Provides a range of spring-boot-starter-* artifacts that contains what you need to get up and running fast • Customise when you need!
  17. 17. Let’s BOOT an application!
  18. 18. Versions • Current stable: 1.3.5
 • Very soon arriving: 1.4.0
 
 We will be using 1.3.5 for the demo today, but have a look at the new features in 1.4.0 towards the end.
  19. 19. Our goal • Create a REST web service with Spring Boot, Groovy and Gradle
 • Use case: A simple R/C Car registry!
  20. 20. What we will cover • Creating an application • Executable JAR • Custom banner (because they’re awesome) • Application configuration • Creating REST endpoints • Testing • Security • Actuators
  21. 21. Step 1: 
 Create application and run it
  22. 22. Step 1: Takeaways • @SpringBootApplication-annotation:
 
 A convenience annotation combining @EnableAutoConfiguration, @Configuration and @ComponentScan
 • We start our application with SpringApplication.run()
  23. 23. Step 2: 
 Executable JAR
  24. 24. Step 2: Takeaways • Add spring-boot-gradle-plugin (or spring-boot-maven- plugin) • Application JAR can then be run as an executable If linked as a service from /etc/init.d you will be able to run the application as a daemon and use start, stop and status arguments
  25. 25. Step 3: 
 Custom banner
  26. 26. Step 3: Takeaways • Well… It is very cool!
  27. 27. Step 4: 
 Application configuration
  28. 28. Step 4: Takeaways • Configuration provided with @Configuration annotated class(es) • Provide beans using @Bean annotated methods
 Configuration properties can be declared using .properties or .yaml files both in- and outside your application
 http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-application-property-files
  29. 29. Step 5: 
 Service endpoint
  30. 30. Step 5: Takeaways • Add endpoints with @RestController and @RequestMapping annotations • No further configuration needed

  31. 31. Step 6: 
 Testing
  32. 32. Step 6: Takeaways • Easy testing of endpoints using RestTemplate • Point your integration test to your application using @SpringApplicationConfiguration(AppClass.class) • Configure random testing port using @WebIntegrationTest(randomPort = true) and obtain the port using @Value('${local.server.port}')

  33. 33. Step 7: 
 Security
  34. 34. Step 7: Takeaways • Simply adding spring-security to class path enables security • @EnableWebSecurity disables default configuration and allows us to customise security • Extend WebSecurityConfigurerAdapter to customise security

  35. 35. Step 8: 
 Security 2
  36. 36. Step 8: Takeaways • Use TestRestTemplate for additional functionality in a test context
 NOTE: Disabling CSRF should only be done for quick testing and prototyping
  37. 37. Step 9: 
 Actuators
  38. 38. Step 9: Takeaways • Actuators are a set of endpoints exposing useful information and controls for your application
 Full list of Actuators: 
 http://docs.spring.io/spring-boot/docs/1.3.3.RELEASE/ reference/htmlsingle/#production-ready-endpoints
  39. 39. What’s new in 1.4.0?
  40. 40. Startup failure analysis
  41. 41. New test annotation • @SpringBootTest with parameters is used instead of @SpringApplicationConfiguration, @IntegrationTest and @WebIntegrationTest • @LocalServerPort for injecting the port of the web server used during test
  42. 42. Upgraded dependencies • Based on Spring 4.3 • Default JPA persistence provider is Hibernate 5, up from 4.3
  43. 43. Image banners!
  44. 44. New annotation for mocking existing beans • @MockBean for mocking existing beans in your application
 
 
 • @SpyBean for spying existing beans
  45. 45. • See the rest here: 
 https://github.com/spring-projects/spring-boot/wiki/ Spring-Boot-1.4-Release-Notes
  46. 46. That’s it. Simply.
  47. 47. Thank you! twitter.com/jaranflaath jaran.flaath@gmail.com Image CC BY-SA 4.0 Ashashyou (https://commons.wikimedia.org/wiki/User:Ashashyou)

×