spring boot - berlin expert days › 2014 › files › slides › springboot.pdf · 2016-01-15 ·...

36
Spring Boot Eberhard Wolff Freelancer Head Technology Advisory Board adesso AG http://ewolff.com

Upload: others

Post on 27-Jun-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Spring Boot

Eberhard Wolff Freelancer

Head Technology Advisory Board adesso AG

http://ewolff.com

Page 2: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Prep demo •  Web Browser localhost:8080 •  IDE •  Terminal in Project Directory

Page 3: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

What does it take to implement a

Java Web Application?

Page 4: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Any non-Java guys in the room?

Page 5: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Java

AppServer

Libraries

Build

WAR

Page 6: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Java

AppServer

Libraries

Build

WAR

Page 7: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Enter Spring Boot

Page 8: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Spring Boot Demo

Page 9: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Demo •  Project simplest-spring-boot •  Launch ControllerAndMain •  Open http://localhost:8080 •  Show main •  Explain @EnableAutoConfiguration •  Explain @RestController and

@RequestMapping •  Show pom.xml (parent, starter, maven

Plugin) •  Show test

Page 10: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Spring Boot •  Build much easier •  Supports Gradle, too •  Not limited to simple application •  Can add any other library

•  Application much easier to test, debug etc

•  Simple code

Page 11: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Let‘s add Spring Data

JPA!

Page 12: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Spring Data JPA •  Makes implementation of

repositories trivial

•  Just provide an interface

•  Needs JPA infrastructure of course

Page 13: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Spring Boot + Spring Data JPA Demo

Page 14: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Demo: Spring Data JPA •  Show pom.xml: Just added

spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf

•  Show CustomerRepository •  That is it – no more configuration •  No DataSource, no nothing •  pom.xml: Show hsql.jar dependency •  Note: transactional tests

Page 15: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Behind the Scenes •  DataSource for HSQL created •  JPA infrastructure created •  Thymeleaf infrastructure created

•  How does it work? •  Convention over configuration

Page 16: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Spring Boot •  Creates sensible infrastructure

defaults •  i.e. DataSource if HSQL is on the

classpath •  Done by *AutoConfiguration classes

Page 17: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Auto Configuration

Page 18: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Demo Auto Configuration •  Show DataSourceAutoConfiguration •  Show EmbeddedConfiguration •  Show *AutoConfiguration •  Explain: HibernateJpaAutoConfigure

depends on Hibernate classes. Those are included in the dependencies.

Page 19: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Spring Boot Starter •  Support for specific frameworks

amqp

aop

batch

data-jpa data-mongodb data-rest

integration

jdbc mobile

redis

security test web websocket

actuator remote-shell

jetty tomcat

log4j logback

Page 20: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Spring Boot for Dev

Page 21: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Dev •  Turn Around

•  Thymeleaf Templates can be changed on the fly

•  …same with class files •  Spring Loaded makes reloading

more powerful

Page 22: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Spring Bootfor DevDemo

Page 23: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Demo Dev Turn Around •  Change template •  Reload page •  Show application.properties

•  Change code •  Reload page •  Show Spring Loaded •  Run configuration: -javaagent:/Users/wolff/

springloaded-1.1.5.RELEASE.jar -noverify

Page 24: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Spring Boot for Ops

Page 25: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

CRaSH Shell •  Ever ssh’d into your application? •  Enter CRaSH •  External library integrated into

Spring Boot •  Alternative approach to operations

Page 26: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Spring BootCRaSH Demo

Page 27: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Demo CRaSH •  ssh -p 2000 user@localhost •  Password in log output •  help •  Mention jpa / jdbc / problems •  thread top CTRL-C •  metrics •  dashboard

Page 28: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Actuator •  Provide information about the

application •  Via http / JSON •  Can be evaluated by monitoring

tools etc. •  Another alternative approach to

monitoring

Page 29: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Spring BootActuator

Demo

Page 30: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Actuator Demo •  Show pom.xml – spring-boot-

starter-actuator •  Open

http://localhost:8080/monitor.html

•  Show metrics / trace •  Show info and

application.properties

Page 31: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Deploy •  Just package everything in an

executable JAR •  …or a WAR

•  Based on Maven or Gradle

•  Build in configuration (YAML, properties etc.)

Page 32: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Spring BootDeploy Demo

Page 33: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Deploy Demo •  mvn package

•  Change packaging to war •  mvn package again •  Show java –jar with WAR •  mvn spring-boot:run

Page 34: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Conclusion •  Easy to start •  Can add libraries and features as

needed •  Dev: Quick turn around •  Ops: Integrated monitoring •  Ops: Easy deployment •  Didn’t show Groovy support

Page 35: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Links http://start.spring.io/ http://projects.spring.io/spring-boot/ https://github.com/spring-projects/spring-boot https://github.com/ewolff/spring-boot-demos https://spring.io/guides/gs/spring-boot/ https://spring.io/guides/gs/actuator-service/ https://spring.io/guides/gs/spring-boot-cli-and-js/

Page 36: Spring Boot - Berlin Expert Days › 2014 › files › slides › SpringBoot.pdf · 2016-01-15 · spring-boot-starter-data-jpa and spring-boot-starter-thymeleaf • Show CustomerRepository

Eberhard Wolff - @ewolff

Thank You!!