Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Spring Boot 1.3 News #渋谷Java

8,847 views

Published on

どこよりも早いSpring Boot 1.3解説
http://shibuya-java.connpass.com/event/16867/

Published in: Technology

Spring Boot 1.3 News #渋谷Java

  1. 1. Spring Boot 1.3 News earlier than anywhere else Shibuya-Java 2015-08-01 @making (Toshiaki Maki)
  2. 2. About me • @making • Spring enthusiast/contributor
  3. 3. Spring Boot http://blog.pivotal.io/pivotal-cloud-foundry/features/mapping-the-cloud-native-journey
  4. 4. Spring Boot http://blog.pivotal.io/pivotal-cloud-foundry/features/mapping-the-cloud-native-journey 1.4 M Downloads a month!!!
  5. 5. Spring Boot 1.3! will be released @ 2015-09 Current version is 1.3.0.RC2
  6. 6. Quick Start with Spring Initializer w/ STS
  7. 7. Quick Start with Spring Initializer w/ STS
  8. 8. Quick Start with Spring Initializer w/ IDEA
  9. 9. Quick Start with Spring Initializer w/ IDEA
  10. 10. • Spring 4.2 Support • New AutoConfigures • Non-functionalities • DevOps Highlights of Spring Boot 1.3 https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.3-Release-Notes
  11. 11. Today s Demo Sources https://github.com/making/ demo-spring-boot-1.3
  12. 12. • Spring 4.2 Support • New AutoConfigures • Non-functionalities • DevOps Highlights of Spring Boot 1.3
  13. 13. Spring 4.2 Support • Server Sent Event (SSE) • Cross Origin Resource Sharing (CORS) • ScriptEngineView • CompletableFuture • and so on… Released Yesterday! https://spring.io/blog/2015/07/31/spring-framework-4-2-goes-ga
  14. 14. • Spring 4.2 Support • New AutoConfigures • Non-functionalities • DevOps Highlights of Spring Boot 1.3
  15. 15. New AutoConfigures • Cache • OAuth2 • Spring Session • jOOQ • EmbeddedMongoDB
  16. 16. Cache AutoConfigure for Spring Cache Abstraction <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-cache</artifactId>
 </dependency>
  17. 17. Cache@EnableCaching
 @SpringBootApplication
 @RestController
 public class Demo {
 @Autowired WeatherService service;
 @RequestMapping
 String hello() {
 long start = System.currentTimeMillis();
 String result = service.getWeather("Tokyo");
 long elapsed = System.currentTimeMillis() - start;
 return result + " took " + elapsed + " [ms]";
 }
 public static void main(String[] args) {
 SpringApplication.run(Demo.class, args);
 }
 }
  18. 18. Cache @CacheConfig(cacheNames = "weather")
 @Service
 class WeatherService {
 
 @Cacheable
 public String getWeather(String where) {
 // Access OpenWeatherMap API;
 }
 }
  19. 19. Cache @CacheDefaults(cacheName = "weather")
 @Service
 class WeatherService {
 
 @CacheResult
 public String getWeather(String where) {
 // Access OpenWeatherMap API;
 }
 } Standard JCache API is also available
  20. 20. Cache
  21. 21. Cache Managers •ConcurrentHashMap •EhCache •Hazelcast •Infinispan •JCache (JSR 107) •Redis •Guava See Samples https://github.com/making/demo-spring-boot-1.3 https://blog.ik.am/#/entries/339
  22. 22. OAuth2 AutoConfigure for Spring Security OAuth2 <dependency>
 <groupId>org.springframework.security.oauth</groupId>
 <artifactId>spring-security-oauth2</artifactId>
 </dependency>
  23. 23. OAuth2 @SpringBootApplication @RestController public class Demo { @RequestMapping("/") String hello() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(Demo.class, args); } }
  24. 24. OAuth2 @SpringBootApplication @EnableAuthorizationServer @EnableResourceServer @RestController public class Demo { @RequestMapping("/") String hello() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(Demo.class, args); } } security.user.name=user security.user.password=password security.oauth2.client.client-id=foo security.oauth2.client.client-secret=bar
  25. 25. OAuth2 $ curl localhost:8080 { "error": "unauthorized", "error_description": "Full authentication is required to access this resource" }
  26. 26. OAuth2 $ curl foo:bar@localhost:8080/oauth/token -d grant_type=password -d username=user -d password=password -d scope=read { "access_token": "43a001d3-862f-4f02-a60f-b04d0988c24c", "token_type": "bearer", "refresh_token": "e4af4aac-eb8e-423b-b3a9-a73ba0f81fd1", "expires_in": 43199, "scope": "read" } Client ID/Secret Resource Owner s username/password
  27. 27. OAuth2 $ curl -H "Authorization: Bearer 43a001d3-862f-4f02-a60f-b04d0988c24c" localhost: 8080 Hello World!
  28. 28. OAuth2 SSO @SpringBootApplication @EnableOAuthSso @RestController public class Demo { @RequestMapping("/") String hello(OAuth2Authentication auth) { return "Hello " + auth.getName(); } public static void main(String[] args) { SpringApplication.run(Demo.class, args); } }
  29. 29. OAuth2 SSO security.oauth2.client.client-id=5f6623be1882438a166a
 security.oauth2.client.client-secret=fb38ecb19304645292ace4e3cfc8ba3102c44dc8
 security.oauth2.client.access-token-uri=https://github.com/login/oauth/access_token
 security.oauth2.client.user-authorization-uri=https://github.com/login/oauth/authorize
 security.oauth2.client.client-authentication-scheme=form
 security.oauth2.resource.user-info-uri=https://api.github.com/user
 security.oauth2.resource.prefer-token-info=false
  30. 30. OAuth2 SSO
  31. 31. OAuth2 SSO security.oauth2.client.client-id=746653690954-hheiimv40v167fp6f26g
 security.oauth2.client.client-secret=jo7Ee9oHJY2i9DeOWHXuMcD-
 security.oauth2.client.access-token-uri=https://www.googleapis.com/oauth2/v3/token
 security.oauth2.client.user-authorization-uri=https://accounts.google.com/o/oauth2/auth
 security.oauth2.client.client-authentication-scheme=form
 security.oauth2.client.scope=profile,email
 security.oauth2.resource.user-info-uri=https://www.googleapis.com/plus/v1/people/me
 security.oauth2.resource.prefer-token-info=false Goole+ API is also available!!
  32. 32. OAuth2 SSO
  33. 33. jOOQ AutoConfigure for jOOQ <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-jooq</artifactId>
 </dependency>
  34. 34. jOOQ @Repository
 public class CustomerRepository {
 @Autowired
 DSLContext dslContext;
 
 public List<Customer> findAll() {
 return dslContext.select()
 .from(CUSTOMERS)
 .orderBy(CUSTOMERS.FIRST_NAME.asc())
 .fetchInto(Customer.class);
 }
 } AutoConfigured Exception Handler, TransactionManager… are also configured
  35. 35. Spring Session AutoConfigure for Spring Session <dependency>
 <groupId>org.springframework.session</groupId>
 <artifactId>spring-session</artifactId>
 </dependency> <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-redis</artifactId>
 </dependency>
  36. 36. Spring Session @SpringBootApplication @RestController public class Demo { @Value("${server.port:8080}") int port; @RequestMapping("/") String hello(HttpSession session) { return "port=" + port + ", id=" + session.getId(); } public static void main(String[] args) { SpringApplication.run(Demo.class, args); } } Nothing special!
  37. 37. Spring Session $ java -jar demo.jar --server.port=8080 $ java -jar demo.jar --server.port=8081
  38. 38. Spring Session
  39. 39. Spring Session
  40. 40. Spring Session
  41. 41. EmbeddedMongoDB AutoConfigure for Embedded Mongo <dependency>
 <groupId>de.flapdoodle.embed</groupId>
 <artifactId>de.flapdoodle.embed.mongo</artifactId>
 </dependency> Automatically used
  42. 42. • Spring 4.2 Support • New AutoConfigures • Non-functionalities • DevOps Highlights of Spring Boot 1.3
  43. 43. Non-functionalities • OpenTSDB Metrics Writer • StatsD Metrics Writer • New Healthcheck
  44. 44. OpenTSDB Metrics Writer @Bean @ExportMetricWriter @ConfigurationProperties("metrics.export") MetricWriter metricWriter() { return new OpenTsdbMetricWriter(); } metrics.export.url=http://localhost:4242/api/put Export metrics to
  45. 45. StatsD Metrics Writer Export metrics to StatsD @Bean
 @ExportMetricWriter
 MetricWriter metricWriter( @Value("${statsd.prefix}") String prefix,
 @Value("${statsd.host}") String host,
 @Value("${statsd.port}") int port) {
 return new StatsdMetricWriter(prefix, host, port);
 } statsd.prefix=demo statsd.host=localhost statsd.port=8125
  46. 46. StatsD Metrics Writer StatsD + Graphite + Grafana https://github.com/kamon-io/docker-grafana-graphite
  47. 47. New Health Check • Elasticsearch • Email • JMS
  48. 48. Highlights of Spring Boot 1.3 • Spring 4.2 Support • New AutoConfigures • Non-functionalities • DevOps
  49. 49. DevOps • Ascii Color Banner • Systemd Service • DevTools
  50. 50. Ascii Color Banner ${AnsiColor.BRIGHT_GREEN}My Application ${AnsiColor.BRIGHT_YELLOW}Hello!!${AnsiColor.DEFAULT} src/main/resources/banner.txt
  51. 51. Ascii Color Banner
  52. 52. Systemd Service $ mvn package $ cp target/*.jar /var/demo/demo <plugin> <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
 <configuration>
 <executable>true</executable>
 </configuration>
 </plugin>
  53. 53. Systemd Service $ systemctl start demo $ systemctl enable demo [Unit] Description=demo After=syslog.target [Service] ExecStart=/var/demo/demo [Install] WantedBy=multi-user.target /etc/systemd/system/demo.service
  54. 54. DevTools • Disabling template cache • Auto restart Class Loader • Live reload browser • Remote debug & restart
  55. 55. DevTools <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency>
  56. 56. Disabling template cache spring.thymeleaf.cache=false spring.freemarker.cache=false spring.groovy.template.cache=false spring.velocity.cache=false spring.mustache.cache=false
  57. 57. spring.thymeleaf.cache=false spring.freemarker.cache=false spring.groovy.template.cache=false spring.velocity.cache=false spring.mustache.cache=false No longer needed!! Disabling template cache
  58. 58. Auto restart Class Loader Demo https://blog.ik.am/#/entries/349
  59. 59. Live reload browser Demo
  60. 60. Remote debug & restart https://www.youtube.com/watch?v=A70NMxV13TI
  61. 61. Wrap Up Spring 4.2 • Server-Sent Events • CORS • ScriptEngineView • CompletableFuture New AutoConfigures • Cache • OAuth2 • Spring Session • jOOQ Non-functionalities • OpenTSDB Metrics • StatsD Metrics • New Healthcheck DevOps • Ascii Color Banner • Systemd Service • DevTools
  62. 62. Announce!! • Spring in Summer • 2015-08-28(Fri.)09:30 - 18:30 • GranTokyo South Tower https://jsug.doorkeeper.jp/events/27682 Largest Spring Event in Japan!!
  63. 63. Announce!! • JJUG LT Festival!! • 2015-08-10(Mon.)19:00 - 21:00 https://jjug.doorkeeper.jp/events/28181

×