Introduction to Spring Boot!

2,861 views
2,558 views

Published on

Published in: Software, Technology, Education
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,861
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
97
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

Introduction to Spring Boot!

  1. 1. SpringBoot! JakubKubryński/kubrynski.com jk@devskiller.com @jkubrynski
  2. 2. whoami kubrynski.com @jkubrynskijk@devskiller.com
  3. 3. History • 1999 J2EE 1.2 • 2001 xDoclet 1.0 • 2004 Spring Framework 1.0 ● Injection ● POJO oriented ● AOP & transactions • 2006 Java EE 5 • 2013 Spring Boot! kubrynski.com @jkubrynskijk@devskiller.com
  4. 4. Focus source: spring.io kubrynski.com @jkubrynskijk@devskiller.com
  5. 5. Revolution @RestController @EnableAutoConfiguration public class HelloWorld { @RequestMapping("/") public String helloWorld() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(HelloWorld.class, args); } } kubrynski.com @jkubrynskijk@devskiller.com
  6. 6. Key features • Stand-alone Spring applications • No code generation / no XML config • Automatic configuration • Starter dependencies • Embedded Tomcat or Jetty • Production-ready environment kubrynski.com @jkubrynskijk@devskiller.com
  7. 7. Blocks • SpringApplication • @EnableAutoConfiguration • @ConditionalOnClass • @ConditionalOnBean • @ConditionalOnExpression kubrynski.com @jkubrynskijk@devskiller.com @...OnMissing...
  8. 8. Sampleauto-configuration @Configuration @ConditionalOnClass({ MBeanExporter.class }) @ConditionalOnMissingBean({ MBeanExporter.class }) @ConditionalOnExpression("${spring.jmx.enabled:true}") public class JmxAutoConfiguration { ... } kubrynski.com @jkubrynskijk@devskiller.com
  9. 9. Availableauto-configurations ● Batch ● Spring Data, JPA, Hibernate, Mongo, Redis ● JMS, RabbitMQ (AMQP) ● Reactor ● Security ● WebMVC, Thymeleaf, Websocket ● Tomcat and Jetty kubrynski.com @jkubrynskijk@devskiller.com
  10. 10. Starters • spring-boot-starter • spring-boot-starter-web • spring-boot-starter-test • spring-boot-starter-actuator kubrynski.com @jkubrynskijk@devskiller.com
  11. 11. Starters <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> kubrynski.com @jkubrynskijk@devskiller.com
  12. 12. Properties public class MailProperties { @Value(“serverAddress”) private InetAddress serverAddress; } java – jar app.jar –serverAddress=10.0.0.1 kubrynski.com @jkubrynskijk@devskiller.com
  13. 13. Properties @ConfigurationProperties(prefix=”mail”) public class MailProperties { private InetAddress serverAddress; private Resource template; } mail.serverAddress : 84.123.456.32 mail.template : classpath:mail.vm kubrynski.com @jkubrynskijk@devskiller.com
  14. 14. Properties @ConfigurationProperties(prefix=”mail”) public class MailProperties { private InetAddress serverAddress; private Resource template; } mail: serverAddress : 84.123.456.32 template : classpath:mail.vm kubrynski.com @jkubrynskijk@devskiller.com
  15. 15. Tests @SpringApplicationConfiguration(classes = Application.class) @ContextConfiguration(classes = Application, loader = SpringApplicationContextLoader) @IntegrationTest kubrynski.com @jkubrynskijk@devskiller.com
  16. 16. Profiles • default file is application.properties • customize by spring.config.name • spring.profiles.active = production,mysql • configuration per profile: ● application-production.properties ● conference-test.properties kubrynski.com @jkubrynskijk@devskiller.com
  17. 17. Logging • Log4J • Logback • Java Util Logging kubrynski.com @jkubrynskijk@devskiller.com
  18. 18. Security • spring-boot-starter-security • @SecurityAutoConfiguration • SecurityProperties ● security.requireSsl = true ● security.enableCsrf = true kubrynski.com @jkubrynskijk@devskiller.com
  19. 19. UserInterface • Thymeleaf • Template engine for XML/XHTML/HTML5 • Customizable ● spring.thymeleaf.prefix=classpath:/templates/ ● spring.thymeleaf.suffix=.html ● spring.thymeleaf.mode=HTML5 ● spring.thymeleaf.encoding=UTF-8 kubrynski.com @jkubrynskijk@devskiller.com
  20. 20. Productionready • Monitoring endpoints ● /health ● /info ● /metrics ● /trace • JMX / SSH • Auditing kubrynski.com @jkubrynskijk@devskiller.com
  21. 21. WAR @EnableAutoConfiguration public class WebApp extends SpringBootServletInitializer{ @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(SampleApplication.class); } } kubrynski.com @jkubrynskijk@devskiller.com
  22. 22. Monitoring application ● ApplicationPidListener ● SpringApplication.addListeners(...) ● META-INF/spring.factories org.springframework.context.ApplicationListener= org.springframework.boot.actuate.system.ApplicationPidListener kubrynski.com @jkubrynskijk@devskiller.com
  23. 23. Rapidprototyping ● Spring Boot CLI ● $ spring run app.groovy ● $ spring test tests.groovy kubrynski.com @jkubrynskijk@devskiller.com
  24. 24. Howdoesithelp? ● Dramatically reduces boilerplate code ● Enables polyglot ● Simplifies integration testing ● Simplifies environment maintenance kubrynski.com @jkubrynskijk@devskiller.com
  25. 25. It'sSpring kubrynski.com @jkubrynskijk@devskiller.com
  26. 26. Livecoding “Talkischeap –showmethecode” kubrynski.com @jkubrynskijk@devskiller.com
  27. 27. Youhavequestions I(probably)haveanswers kubrynski.com @jkubrynskijk@devskiller.com
  28. 28. END! THANKYOU kubrynski.com @jkubrynskijk@devskiller.com

×