Slide 1

Slide 1 text

Spring Boot for the Java EE Developer

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Overview • What is Spring Boot? • Spring Boot in a Java EE App Server • Java EE in Spring Boot

Slide 5

Slide 5 text

WARning!! may contain traces of Spring boot 1.3

Slide 6

Slide 6 text

What is Spring Boot? • Convention over configuration • Embedded Servlet Container • Zero XML

Slide 7

Slide 7 text

“Spring Boot is like pair programming with the Spring Team”

Slide 8

Slide 8 text

“We searched stackoverflow.com so you don’t have to”

Slide 9

Slide 9 text

Demo Spring Boot in 5 minutEs

Slide 10

Slide 10 text

Application Servers Deploying Spring Boot Apps to Java EE servers

Slide 11

Slide 11 text

Your Code Spring Libs Java EE Libs Servlet Container .jar java -jar myapp.jar

Slide 12

Slide 12 text

App Server Your Code Spring Libs Java EE Libs .war ./bin/asadmin start-domain

Slide 13

Slide 13 text

Converting an app org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat org.springframework.boot spring-boot-starter-validation

Slide 14

Slide 14 text

Converting an app javax javaee-api 7.0 provided javax.servlet javax.servlet-api provided or

Slide 15

Slide 15 text

Converting an app @SpringBootApplication public class DemoApplication extends SpringBootServletInitializer { }

Slide 16

Slide 16 text

Demo Spring Boot on payara

Slide 17

Slide 17 text

Application Server Support • JNDI Support • DataSource / JMS / JTA / Java MAIL • Environment properties • Websphere Hibernate support • Wildfly & TomEE integration tests

Slide 18

Slide 18 text

Java EE Consuming Java EE From Boot

Slide 19

Slide 19 text

Convention & Configuration • Add a *-starter POM • Inject & use beans • Customize with application.properties • If it’s not enough: Define your own @Configuration

Slide 20

Slide 20 text

Servlets & Filters • There’s no web.xml • Register using Spring Beans • Servlet or filter directly • Using *registration beans • or ServletContext Initializer

Slide 21

Slide 21 text

Demo Filter

Slide 22

Slide 22 text

JPA • Entity scanning from @SpringBootApplication • Auto-configured in-memory database • or use application.properties spring.datasource.url=jdbc:mysql://localhost/test spring.datasource.username=dbuser spring.datasource.password=dbpass spring-boot-starter-jpa

Slide 23

Slide 23 text

Demo JPA

Slide 24

Slide 24 text

JMS • ActiveMQ / Artemis / HornetQ • Sending • Receiving // inject JmsMessagingTemplate template.convertAndSend(“dest”, “message”); @JmsListener(destination = "someQueue") public void processMessage(String content) { // ... } spring-boot-starter-artemis

Slide 25

Slide 25 text

Demo JMS

Slide 26

Slide 26 text

Websockets • Spring’s Support (with sockjs fallback) spring-boot-starter-websocket @SpringBootApplication @EnableWebSocket public class Application implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { registry.addHandler(echoHandler(), "/echo").withSockJS(); } @Bean public WebSocketHandler echoWebSocketHandler() { return new EchoWebSocketHandler(); } }

Slide 27

Slide 27 text

Websockets • JSR 356 Support spring-boot-starter-websocket @ServerEndpoint("/reverse") public class ReverseWebSocketEndpoint { @OnMessage public void handleMessage(Session session, String message) throws IOException { StringBuilder reverse = new StringBuilder(message).reverse(); session.getBasicRemote().sendText("Reversed: " + reverse); } } @Bean public ServerEndpointExporter serverEndpointExporter() { return new ServerEndpointExporter(); }

Slide 28

Slide 28 text

Demo Websockets

Slide 29

Slide 29 text

Bean Validation • JSR-303 & JSR-349 support • Spring MVC DataBinder • and @ConfigurationProperties spring-boot-starter-validation

Slide 30

Slide 30 text

Bean Validation spring-boot-starter-validation @Component @ConfigurationProperties(prefix = "myapp") public class ExampleConfiguration { @Length(min = 8) private String password; public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } #application.properties myapp.password=short

Slide 31

Slide 31 text

Demo Bean validation

Slide 32

Slide 32 text

Caching • JSR-107 Auto-configuration (+ Others) • Spring’s @Cachable annotation spring-boot-starter-cache @Service public class MyService { @Cacheable("mycache") public String lengthy(int id) { // … } }

Slide 33

Slide 33 text

Demo Caching

Slide 34

Slide 34 text

Java mail • Auto-Configuration for java mail • MailSender interface spring-boot-starter-mail SimpleMailMessage message = new SimpleMailMessage(); message.setTo("[email protected]"); message.setText("Hello World!"); mailSender.send(message); spring.mail.host=mymailserver spring.mail.port=8025

Slide 35

Slide 35 text

Demo Java mail

Slide 36

Slide 36 text

Conclusion • Great way to consume Java EE • inside or outside of an App Server • cloud friendly • Go to spring.io for more information

Slide 37

Slide 37 text

Thanks! Questions? @phillip_webb speakerdeck.com/philwebb github.com/philwebb/spring-boot-for-the-java-ee-developer spring.io/blog/2014/11/23/bootiful-java-ee-support-in-spring-boot-1-2