Beruflich Dokumente
Kultur Dokumente
Stphane Nicoll
Pivotal
Unless otherwise indicated, these slides are 2013-2014Pivotal Software, Inc. and licensedunder a
Hello!
@snicoll
https://github.com/snicoll
snicoll@pivotal.io
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
!
!
!
!
A prototyping tool
Only for embedded container apps
Sub-par Spring experience
For Spring beginners only
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Installation
! Requirements:
JDK6+
Maven 3.2+ / Gradle 1.12+
! Tools:
Spring Tool Suite (STS) - IntelliJ IDEA - Netbeans
Spring CLI (from https://start.spring.io or gvm)
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
@RestController
public class HomeController {
@Value("${conference.name:jsug}")
private String conference;
@RequestMapping("/")
public String home() {
return "Hello " + conference;
}
}
9
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
10
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
11
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
13
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
14
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
15
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
RESTful repository
16
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
17
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
@Configuration
public class SecurityConfig extends GlobalAuthenticationConfigurerAdapter {
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("hero").password("hero").roles("HERO", "USER").and()
.withUser("user").password("user").roles("USER");
}
}
18
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
20
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
21
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-remote-shell</artifactId>
</dependency>
22
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="${speaker.firstName} + ' ' + ${speaker.lastName}">View speaker</title>
</head>
<body>
<div class="profile">
<h1 class="name" th:text="${speaker.firstName} + ' ' + ${speaker.lastName}">Stephane Nicoll</h1>
<div>
<p th:text="${speaker.bio}">Sample Biography.</p>
</div>
<div>
<a th:href="'http://twitter.com/' + ${speaker.twitter}" class="twitter" th:text="'@' + $
{speaker.twitter}">@snicoll</a>
</div>
</div>
</body>
</html>
24
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
$ mvn package
$ cf push jsug -p target/jsug-0.0.1-SNAPSHOT.jar
$ cf scale jsug -i 4
25
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Starter POMs
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
compile("org.springframework.boot:spring-boot-starter-web")
26
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
27
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
28
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
29
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
30
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
! This default implementation will be shipped with the auto-config project but
should not be used if the application provides one.
31
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Auto-configuration example
@Configuration
@ConditionalOnClass(HelloService.class)
public class HelloServiceAutoConfiguration {
@ConditionalOnMissingBean
@Bean
public HelloService helloService() {
return new ConsoleHelloService();
}
}
32
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
demo.hello.HelloServiceAutoConfiguration
33
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
<dependency>
<groupId>org.test.jsug</groupId>
<artifactId>hello-service-auto-configuration</artifactId>
<version>...</version>
</dependency>
34
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
@Bean
public HelloService helloService() {
return () ->
LoggerFactory.getLogger(DemoApplication.class)
.info("Hello from logs");
}
}
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
@ConfigurationProperties("hello")
public class HelloProperties {
private String prefix = "Hello ";
private String target;
// getters and setters
}
37
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
@EnableConfigurationProperties(HelloProperties.class)
@Configuration
@ConditionalOnClass(HelloService.class)
public class HelloServiceAutoConfiguration {
38
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Document properties
@ConfigurationProperties("hello")
public class HelloProperties {
/**
* Prefix of welcome message.
*/
private String prefix = "Hello ";
/**
* Target of welcome message.
*/
private String target;
// getters and setters
}
41
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
https://spring.io powered by
github.com/spring-io/sagan
42
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll
Links
! https://projects.spring.io/spring-boot/
! https://github.com/spring-projects/spring-boot
! https://spring.io/guides
! https://spring.io/blog
! https://spring.io/questions
! https://www.youtube.com/user/SpringSourceDev
@springboot
43
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@springcentral
@snicoll
Twitter: twitter.com/springcentral
YouTube: spring.io/video
! Follow @springboot
LinkedIn: spring.io/linkedin
! StackOverflow - #spring-boot
44
Unless otherwise indicated, these slides are 2013-2015Pivotal Software, Inc. and licensedunder a
@snicoll