introduction to spring boot!
DESCRIPTION
TRANSCRIPT
![Page 3: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/3.jpg)
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 @[email protected]
![Page 5: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/5.jpg)
Revolution
@RestController@EnableAutoConfigurationpublic class HelloWorld {
@RequestMapping("/") public String helloWorld() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(HelloWorld.class, args); }
}
kubrynski.com @[email protected]
![Page 6: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/6.jpg)
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 @[email protected]
![Page 7: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/7.jpg)
Blocks
• SpringApplication
• @EnableAutoConfiguration
• @ConditionalOnClass
• @ConditionalOnBean
• @ConditionalOnExpression
kubrynski.com @[email protected]
@...OnMissing...
![Page 8: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/8.jpg)
Sample auto-configuration
@Configuration
@ConditionalOnClass({ MBeanExporter.class })
@ConditionalOnMissingBean({ MBeanExporter.class })
@ConditionalOnExpression("${spring.jmx.enabled:true}")
public class JmxAutoConfiguration {
...
}
kubrynski.com @[email protected]
![Page 9: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/9.jpg)
Available auto-configurations
● Batch● Spring Data, JPA, Hibernate, Mongo, Redis● JMS, RabbitMQ (AMQP)● Reactor● Security● WebMVC, Thymeleaf, Websocket● Tomcat and Jetty
kubrynski.com @[email protected]
![Page 10: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/10.jpg)
Starters
• spring-boot-starter
• spring-boot-starter-web
• spring-boot-starter-test
• spring-boot-starter-actuator
kubrynski.com @[email protected]
![Page 11: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/11.jpg)
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 @[email protected]
![Page 12: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/12.jpg)
Properties
public class MailProperties {
@Value(“serverAddress”)
private InetAddress serverAddress;
}
java – jar app.jar –serverAddress=10.0.0.1
kubrynski.com @[email protected]
![Page 13: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/13.jpg)
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 @[email protected]
![Page 14: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/14.jpg)
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 @[email protected]
![Page 15: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/15.jpg)
Tests
@SpringApplicationConfiguration(classes =
Application.class)
@ContextConfiguration(classes = Application,
loader = SpringApplicationContextLoader)
@IntegrationTest
kubrynski.com @[email protected]
![Page 16: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/16.jpg)
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 @[email protected]
![Page 18: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/18.jpg)
Security
• spring-boot-starter-security
• @SecurityAutoConfiguration
• SecurityProperties● security.requireSsl = true● security.enableCsrf = true
kubrynski.com @[email protected]
![Page 19: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/19.jpg)
User Interface
• 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 @[email protected]
![Page 20: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/20.jpg)
Production ready
• Monitoring endpoints● /health● /info● /metrics● /trace
• JMX / SSH
• Auditing
kubrynski.com @[email protected]
![Page 21: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/21.jpg)
WAR
@EnableAutoConfiguration
public class WebApp extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder
configure(SpringApplicationBuilder application) {
return application.sources(SampleApplication.class);
}
}
kubrynski.com @[email protected]
![Page 22: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/22.jpg)
Monitoring application
● ApplicationPidListener
● SpringApplication.addListeners(...)
● META-INF/spring.factoriesorg.springframework.context.ApplicationListener=\
org.springframework.boot.actuate.system.ApplicationPidListener
kubrynski.com @[email protected]
![Page 23: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/23.jpg)
Rapid prototyping
● Spring Boot CLI
● $ spring run app.groovy
● $ spring test tests.groovy
kubrynski.com @[email protected]
![Page 24: Introduction to Spring Boot!](https://reader030.vdocuments.mx/reader030/viewer/2022012405/54b6c3484a7959d7268b461a/html5/thumbnails/24.jpg)
How does it help?
● Dramatically reduces boilerplate code
● Enables polyglot
● Simplifies integration testing
● Simplifies environment maintenance
kubrynski.com @[email protected]