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.

ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説

7,888 views

Published on

JJUG CCC 2018 Springの資料です。

Published in: Technology
  • Be the first to comment

ReactiveだけじゃないSpring 5 & Spring Boot 2新機能解説

  1. 1. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 1
  2. 2. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ 2
  3. 3. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ 
 ▸ ▸ ▸ 3
  4. 4. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ 4
  5. 5. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ ▸ 5
  6. 6. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ 
 ▸ 
 ▸ ▸ ▸ 6
  7. 7. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ 
 ▸ ▸ 7
  8. 8. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 8 1. Core 2. Web 3. Data4. Security 5. Test 6. Boot
  9. 9. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 9 1. Core 2. Web 3. Data4. Security 5. Test 6. Boot
  10. 10. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ ▸ @NonNull / @Nullable 10
  11. 11. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ 
 
 ▸ 😖 11
  12. 12. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ 12
  13. 13. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ 13
  14. 14. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ requires 14 module my.app { requires spring.jdbc; requires spring.webmvc; requires spring.context; }
  15. 15. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ ▸ ▸ 15※SpringOne 2017 Spring Framework 5.0 on JDK 8 & 9
  16. 16. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ ▸ 16
  17. 17. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ 
 ▸ 17
  18. 18. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 18 # #Mon Jan 29 13:18:40 JST 2018 com.example.web.controller.TodoController=org.s pringframework.stereotype.Component com.example.persistence.repository.TodoReposito ryImpl=org.springframework.stereotype.Component com.example.service.TodoServiceImpl=org.springf ramework.stereotype.Component com.example.web.config.MvcConfig=org.springfram ework.stereotype.Component com.example.persistence.config.PersistenceConfi g=org.springframework.stereotype.Component com.example.service.config.ServiceConfig=org.sp ringframework.stereotype.Component ▸ Bean
  19. 19. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 19 ▸ https://twitter.com/snicoll/status/957893939054415872
  20. 20. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 @NonNull/@Nullable ▸ ▸ ▸ ▸ ▸ ▸ 20
  21. 21. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 21 1. Core 2. Web 3. Data4. Security 5. Test 6. Boot
  22. 22. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ WebMvcConfigurerAdapter ▸ ▸ 22
  23. 23. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ PushBuilder ▸ ▸ 
 23 @GetMapping("/push") public String push(PushBuilder pushBuilder) { // … }
  24. 24. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ @Email @NotEmpty @NotBlank ▸ ▸ @Past @Future ▸ ▸ List<@Size(min = 3) String>
 24 GlassFish 
 
 Java EE 8 
 -Bean Validation 2.0 -
  25. 25. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 @Configuration public class MvcConfig implements WebMvcConfigurer { // … } @Configuration public class MvcConfig extends WebMvcConfigurerAdapter { // … } WebMvcConfigurerAdapter 25 ▸ WebMvcConfigurer
  26. 26. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 @PostMapping public String post(HelloForm helloForm) { // … } 26 public class HelloForm { private final String message; public HelloForm(String message) { this.message = message; } public String getMessage() { return message; } } final getter 
 (setter ) 

  27. 27. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ -parameters 
 ▸ -parameters ▸ 😅 27
  28. 28. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ @DateTimeFormat ▸ ▸ ▸ ▸ ▸ 28
  29. 29. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ MaxUploadSizeExceededException ▸ ▸ ResponseStatusException ▸ ▸ ExceptionHandler ▸ RedirectAttribute 29
  30. 30. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 30 1. Core 2. Web 3. Data4. Security 5. Test 6. Boot
  31. 31. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ 31
  32. 32. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ Optional ▸ 32 public interface CrudRepository<T, ID> extends Repository<T, ID> { // Iterable<S> save(Iterable<S> entities) <S extends T> Iterable<S> saveAll(Iterable<S> entities); // T find(ID id) Optional<T> findById(ID id); // …
  33. 33. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 33 // Iterable<T> findAllById(Iterable<ID> ids); // boolean exists(ID id) boolean existsById(ID id); // void delete(ID id) void deleteById(ID id); // void delete(Iterable<? extends T> entities) void deleteAll(Iterable<? extends T> entities); // }
  34. 34. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ JdbcTemplate ▸ 34 public interface EmployeeRepository extends CrudRepository<Employee, Long> { // SQL @Query("SELECT ... FROM employee WHERE ...") List<Employee> findByHogeHoge(...); // CrudRepository
  35. 35. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ 35
  36. 36. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 36 1. Core 2. Web 3. Data4. Security 5. Test 6. Boot
  37. 37. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ DelegatingPasswordEncoder 37
  38. 38. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ 38
  39. 39. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ ▸ ▸ 39
  40. 40. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 40 @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) { http.authorizeRequest() .anyRequest().authenticated(); http.oauth2Login(); } // omitted ※ 
 https://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#jc-oauth2login-javaconfig-wo-boot
  41. 41. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 DelegatingPasswordEncoder ▸ PasswordEncoder DelegatingPasswordEncoder 41 @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure( AuthenticationManagerBuilder auth) auth.inMemoryAuthentication() .withUser("…").password("…").roles("…").and() .withUser("…").password("…").roles("…"); } // omitted Delegating
 PasswordEncoder

  42. 42. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 DelegatingPasswordEncoder ▸ 
 PasswordEncoder 42 Delegating
 Password
 Encoder BCrypt
 Password
 Encoder Pbkdf2
 Password
 Encoder NoOp
 Password
 Encoder {bcrypt}$2a$10$… {pbkdf2}5d623b44… {noop}password
  43. 43. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ 
 PasswordEncoder ▸ ▸ PasswordEncoder 43 DelegatingPasswordEncoder
  44. 44. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 44 1. Core 2. Web 3. Data4. Security 5. Test 6. Boot
  45. 45. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ 45
  46. 46. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ SpringExtension ▸ 46 @ExtendWith(SpringExtension.class) @ContextConfiguration( classes = HelloTestConfig.class) public class HelloTest { @Autowired HelloService service; // … }
  47. 47. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ SpringExtension 
 ParameterResolver 47 @ExtendWith(SpringExtension.class) @ContextConfiguration( classes = HelloTestConfig.class) public class HelloTest { @Test void test(@Autowired HelloService service) { // … } }
  48. 48. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ @SpringJUnitConfig ▸ = @ExtendWith(SpringExtension.class) 
 + @ContextConfiguration ▸ @SpringJUnitWebConfig ▸ = @ExtendWith(SpringExtension.class)
 + @ContextConfiguration + @WebAppConfiguration ▸ @EnabledIf / @DisabledIf ▸ 48
  49. 49. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 49 1. Core 2. Web 3. Data4. Security 5. Test 6. Boot
  50. 50. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ ▸ 50
  51. 51. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ 
 
 ▸ ▸ 
 
 51
  52. 52. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ 
 ▸ 
 ▸ 
 
 
 52
  53. 53. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ -parameters ▸ ▸ 😅 ▸ ▸ 53
  54. 54. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ 54
  55. 55. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ 
 ▸ 
 55
  56. 56. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ WebSecurityConfigurerAdapter 56
  57. 57. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ /actuator ▸ /info /health ▸ 57
  58. 58. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ 
 58 # /shutdown management.endpoint.< >.enabled=true # management.endpoints.web.exposure.include=< >
  59. 59. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ 59 @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.httpBasic(); http.authorizeRequests() .requestMatchers(EndpointRequest.toAnyEndpoint()) .hasRole(" ") .anyRequest().authenticated(); }
  60. 60. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ server.context-path
 server.servlet.context-path 60
  61. 61. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ 61 <!— —> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-properties-migrator</artifactId> <scope>runtime</scope> </dependency>
  62. 62. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 62
  63. 63. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ 63
  64. 64. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 64
  65. 65. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 65 Core JDK 8 JDK 9/10 Web HTTP/2 Bean Validation 2.0 Data Repository API Security OAuth 2.0 DelegatingPasswordEncoder Test JUnit 5 Boot JDK 8/9 Actuator
  66. 66. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ 66
  67. 67. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ 67
  68. 68. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ 68
  69. 69. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ 69
  70. 70. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ ▸ ▸ ▸ ▸ 70
  71. 71. (C) CASAREAL, Inc. All rights reserved. #jjug_ccc #ccc_e3 ▸ 71

×