Slide 1

Slide 1 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 2020年2⽉12⽇ JSUG勉強会 2020その2 川⼝ ⻯太郎(@kawakawaryuryu) Spring Boot 1.5→2.1 バージョンアップを経験して 分かったハマりどころ

Slide 2

Slide 2 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. ⾃⼰紹介 2 • 川⼝ ⻯太郎(かわぐち りゅうたろう) • 所属: ヤフー株式会社 システム統括本部 情報システム本部 • お仕事: 社内ワークフローシステムの開発 • 普段使っている技術 • Spring Boot(Java) • Angular(TypeScript) • Express(Node.js) • Cloud Foundry • Spring歴: 2年半ほど @kawakawaryuryu

Slide 3

Slide 3 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 今⽇お話すること 3 • Boot 1.5→2.1に上げた1事例のお話 • バージョンアップの流れ • 気をつけたことなども紹介 • Boot 2系に上げた時のハマりポイント • 実際に起きたエラーごとに紹介 • バージョンアップを振り返ってみて

Slide 4

Slide 4 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 今⽇お話する技術 4 • Spring Data Jpa • Spring Web Mvc • Mockito • Jackson • Bean Override • UriComponentsBuilder • spring-boot-properties-migrator • (Spring Boot Actuator)

Slide 5

Slide 5 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 前提 5 • Spring Boot 1.5.14→2.1.6 • Mavenで紹介します • スクラム開発で進めている

Slide 6

Slide 6 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. バージョンアップの流れ 6 1. Spring Boot 2系変更点調査 2. コード修正 3. コードレビュー 4. 動作確認 ×リポジトリ数

Slide 7

Slide 7 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 1. Spring Boot 2系変更点調査 7 • 2h使ってSpring Bootの変更点をざっと 調査 • Migration Guide • Release Note • 試しにバージョンアップしてコンパイルやテ ストを実⾏してエラー内容をざっと把握する バージョンアップコストを把握する

Slide 8

Slide 8 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 2. コード修正 8 • 実際にSpring Bootバージョンアップを⾏う • 詳しくは後ほど • ⼩さいリポジトリから対応 →実績を積んでいく • 1スプリントに詰め込みすぎない • ⼀気にやると当初の計画からオーバーしがち

Slide 9

Slide 9 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 3. コードレビュー 9 • チームメンバーにレビュー依頼 • 変更点が多くレビュアーが⾟い モブレビューでレビュー のコストを下げる

Slide 10

Slide 10 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 4. 動作確認 10 • ⼿動によるリグレッションテストを実施 • デグレが起こっていないか確認 • シナリオテストを実施 • ⼀連の動作に問題ないか確認 網羅的に品質を担保

Slide 11

Slide 11 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. Copyright (C) 2019 Yahoo Japan Corporation. All Rights Reserved. コード修正の 具体的な流れと ハマりどころの紹介

Slide 12

Slide 12 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. コード修正の流れ 12 1. Spring Bootのバージョン修正 2. コンパイル→エラーをひたすら修正 3. テスト→エラーをひたすら修正 4. Spring Boot起動 5. 動作確認

Slide 13

Slide 13 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 1. Spring Bootのバージョン修正 13 • 修正前 org.springframework.boot spring-boot-starter-parent 2.1.6.RELEASE org.springframework.boot spring-boot-starter-parent 1.5.14.RELEASE • 修正後

Slide 14

Slide 14 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 2.コンパイル→エラーをひたすら修正 14 $ mvn test-compile

Slide 15

Slide 15 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. コンパイルの前に 15 maven-compiler-pluginを設定してwarningと ⾮推奨ログを表⽰するようにしておくと便利 org.apache.maven.plugins maven-compiler-plugin 3.8.1 true true

Slide 16

Slide 16 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. コンパイルエラー① 16 $ mvn compile [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo --- … [ERROR] /jsug-demo/src/main/java/com/kawakawaryuryu/boot15/demo/service/SampleService.java:[47,47] インタ フェース org.springframework.data.repository.query.QueryByExampleExecutorのメソッド findOneは指定された型に適 用できません。 期待値: org.springframework.data.domain.Example 検出値: java.lang.String 理由: 型変数Sを推論できません (引数の不一致: java.lang.Stringをorg.springframework.data.domain.Exampleに変換できません:)

Slide 17

Slide 17 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. コンパイルエラー① 17 $ mvn compile [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo --- … [ERROR] /jsug-demo/src/main/java/com/kawakawaryuryu/boot15/demo/service/SampleService.java:[47,47] インタ フェース org.springframework.data.repository.query.QueryByExampleExecutorのメソッド findOneは指定された型に適 用できません。 期待値: org.springframework.data.domain.Example 検出値: java.lang.String 理由: 型変数Sを推論できません (引数の不一致: java.lang.Stringをorg.springframework.data.domain.Exampleに変換できません:)

Slide 18

Slide 18 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. findOne(Spring Data Jpa) Boot 1.5 (Spring Data Jpa 1.11) 18 Boot 2.0 (Spring Data Jpa 2.0) • QBE(Query By Example)のみになった SampleEntity entity = sampleRepository.findOne("1"); SampleEntity probe = SampleEntity .builder() .id("1") .build(); Example example = Example.of(probe); SampleEntity entity = sampleRepository.findOne(example); SampleEntity probe = SampleEntity .builder() .id("1") .build(); Example example = Example.of(probe); Optional entity = sampleRepository.findOne(example);

Slide 19

Slide 19 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. その他メソッド(Spring Data Jpa) Boot 1.5 (Spring Data Jpa 1.11) 19 Boot 2.0 (Spring Data Jpa 2.0) Optional entity = sampleRepository.findById("1"); boolean exists = sampleRepository.existsById("1"); sampleRepository.deleteById("1"); sampleRepository.saveAll(sampleEntityList); • Primary key指定のメソッドは~ByIdに変更 SampleEntity entity = sampleRepository.findOne("1"); boolean exists = sampleRepository.exists("1"); sampleRepository.delete("1"); sampleRepository.save(sampleEntityList);

Slide 20

Slide 20 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. Warning① 20 $ mvn compile [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo --- … [WARNING] /jsug-demo/src/main/java/com/kawakawaryuryu/boot15/demo/config/WebMvcConfig.java:[5,57] org.springframework.web.servlet.config.annotationの org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapterは非推奨になりました

Slide 21

Slide 21 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. WebMvcConfigurerAdapterが⾮推奨 Boot 1.5(Spring 4.3) 21 Boot 2.0(Spring 5.0) @Configuration public class WebMvcConfig extends WebMvcConfigurerAdapter { } @Configuration public class WebMvcConfig implements WebMvcConfigurer { } • WebMvcConfigurer(インターフェース)に変更 • WebMvcConfigurerがdefaultメソッドで持つようになった

Slide 22

Slide 22 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. Warning② 22 $ mvn test-compile … [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo --- … [WARNING] /jsug-demo/src/test/java/com/kawakawaryuryu/boot15/demo/service/SampleServiceTest.java:[59,44] org.mockito.MatchersのanyListOf(java.lang.Class)は非推奨になりました

Slide 23

Slide 23 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. テスト対象コード例 23 @Service // テスト対象コード例 public class SampleService { private final DependencyService dependencyService; public SampleService( DependencyService dependencyService) { this.dependencyService = dependencyService; } public void sampleList(List list) { dependencyService.callList(list); }

Slide 24

Slide 24 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. ⼀部Matcherメソッドが⾮推奨 Boot 1.5(Mockito 1) 24 Boot 2.0(Mockito 2) @Test public void testSampleList() { List list = Arrays.asList("hoge", "fuga"); sampleService.sampleList(list); verify(dependencyService) .callList(anyListOf(String.class)); } @Test public void testSampleList() { List list = Arrays.asList("hoge", "fuga"); sampleService.sampleList(list); verify(dependencyService) .callList(anyList()); } • anyXXOf(SomeType.class)が⾮推奨に • Java8から型推論してくれる

Slide 25

Slide 25 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 3.テスト→エラーをひたすら修正 25 $ mvn test

Slide 26

Slide 26 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. テストエラー① 26 $ mvn test [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo --- … java.lang.IllegalStateException: Failed to load ApplicationContext … Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException … Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException

Slide 27

Slide 27 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. テストエラー① 27 $ mvn test [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo --- … java.lang.IllegalStateException: Failed to load ApplicationContext … Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException … Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException

Slide 28

Slide 28 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. InvalidDefinitionException 28 • Jackson 2.9から追加されたクラス com.fasterxml.jackson.core jackson-databind 2.8.11 com.fasterxml.jackson.core jackson-databind 2.9.8 Boot 1.5 Boot 2.0

Slide 29

Slide 29 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. spring-boot-starter-json 29 com.fasterxml.jackson.core jackson-databind ${jackson.version} com.fasterxml.jackson.datatype jackson-datatype-jdk8 ${jackson.version} com.fasterxml.jackson.datatype jackson-datatype-jsr310 ${jackson.version} com.fasterxml.jackson.module jackson-module-parameter-names ${jackson.version} org.springframework.boot spring-boot-starter-json Boot 2から新設

Slide 30

Slide 30 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. テストエラー② 30 $ mvn test [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo --- … java.lang.IllegalStateException: Failed to load ApplicationContext … Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'mappedInterceptor' defined in com.kawakawaryuryu.boot15.demo.config.AppTestConfig: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=appTestConfig; factoryMethodName=mappedInterceptor; initMethodName=null; destroyMethodName=(inferred); defined in com.kawakawaryuryu.boot15.demo.config.AppTestConfig] for bean 'mappedInterceptor': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=appConfig; factoryMethodName=mappedInterceptor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/kawakawaryuryu/boot15/demo/config/AppConfig.class]] bound.

Slide 31

Slide 31 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. テストエラー② 31 $ mvn test [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo --- … java.lang.IllegalStateException: Failed to load ApplicationContext … Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'mappedInterceptor' defined in com.kawakawaryuryu.boot15.demo.config.AppTestConfig: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=appTestConfig; factoryMethodName=mappedInterceptor; initMethodName=null; destroyMethodName=(inferred); defined in com.kawakawaryuryu.boot15.demo.config.AppTestConfig] for bean 'mappedInterceptor': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=appConfig; factoryMethodName=mappedInterceptor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/kawakawaryuryu/boot15/demo/config/AppConfig.class]] bound.

Slide 32

Slide 32 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 例 32 @Configuration public class AppConfig { @Bean public MappedInterceptor mappedInterceptor() { return new MappedInterceptor(new String[]{"/sample"}, new SampleInterceptor()); } } @TestConfiguration public class AppTestConfig { @Bean public MappedInterceptor mappedInterceptor() { return new MappedInterceptor(new String[]{"/**"}, new String[]{"/**"}, new SampleInterceptor()); } } Beanを Overrideして 書き換えている

Slide 33

Slide 33 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. Bean Override禁⽌ 33 • Boot 2.1からBean Overrideはデフォルトで 禁⽌ • 有効にしたい場合は application.yml/propertiesを下記のように する • 基本的にはfalseにしたほうがいい spring: main: allow-bean-definition-overriding: true

Slide 34

Slide 34 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. テストエラー③ 34 $ mvn test [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo --- … [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.532 s <<< FAILURE! - in com.kawakawaryuryu.boot15.demo.service.SampleServiceTest [ERROR] testSampleString(com.kawakawaryuryu.boot15.demo.service.SampleServiceTest) Time elapsed: 0.016 s <<< FAILURE! org.mockito.exceptions.verification.junit.ArgumentsAreDifferent: Argument(s) are different! Wanted: dependencyService.callString(); -> at com.kawakawaryuryu.boot15.demo.service.SampleServiceTest.testSampleString(SampleServiceTest.java:45) Actual invocation has different arguments: dependencyService.callString(null); -> at com.kawakawaryuryu.boot15.demo.service.SampleService.sampleString(SampleService.java:26) at com.kawakawaryuryu.boot15.demo.service.SampleServiceTest.testSampleString(SampleServiceTest.java:45)

Slide 35

Slide 35 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. テストエラー③ 35 $ mvn test [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo --- … [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.532 s <<< FAILURE! - in com.kawakawaryuryu.boot15.demo.service.SampleServiceTest [ERROR] testSampleString(com.kawakawaryuryu.boot15.demo.service.SampleServiceTest) Time elapsed: 0.016 s <<< FAILURE! org.mockito.exceptions.verification.junit.ArgumentsAreDifferent: Argument(s) are different! Wanted: dependencyService.callString(); -> at com.kawakawaryuryu.boot15.demo.service.SampleServiceTest.testSampleString(SampleServiceTest.java:45) Actual invocation has different arguments: dependencyService.callString(null); -> at com.kawakawaryuryu.boot15.demo.service.SampleService.sampleString(SampleService.java:26) at com.kawakawaryuryu.boot15.demo.service.SampleServiceTest.testSampleString(SampleServiceTest.java:45)

Slide 36

Slide 36 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. テスト対象コード例 36 @Service // テスト対象コード例 public class SampleService { private final DependencyService dependencyService; public SampleService( DependencyService dependencyService) { this.dependencyService = dependencyService; } public void sampleString(String value) { dependencyService.callString(value); } public void sampleObject(SampleType sampleType) { dependencyService.callSampleType(sampleType); } }

Slide 37

Slide 37 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. ⼀部Matcherのnon null化 Boot 1.5(Mockito 1) 37 Boot 2.0(Mockito 2) @Test public void testSampleString() { sampleService.sampleString(null); verify(dependencyService) .callString(anyString()); } @Test public void testSampleObject() { sampleService.sampleObject(null); verify(dependencyService) .callSampleType(any(SampleType.class)); } @Test public void testSampleString() { sampleService.sampleString(null); verify(dependencyService) .callString(isNull()); } @Test public void testSampleObject() { sampleService.sampleObject(null); verify(dependencyService) .callSampleType(any()); } • anyXX(), any(SomeType.class)はnull禁⽌ • nullの場合はisNull()かany()を使う • 引数がnullableなのか再度⾒直す

Slide 38

Slide 38 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. テストエラー④ 38 • クエリパラメータが エンコードされなくなったエラー [ERROR] testGetSample(com.kawakawaryuryu.boot15.demo.client.SampleClientTest) Time elapsed: 0.025 s <<< FAILURE! java.lang.AssertionError: Request URI expected: but was: at com.kawakawaryuryu.boot15.demo.client.SampleClientTest.testGetSample(SampleClientTest.java:28)

Slide 39

Slide 39 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. URLの予約⽂字エンコード 39 • 予約⽂字をURLに使⽤するときは %エンコードする • 例: /sample?query=+hoge → /sample?query=%2Bhoge RFC: https://tools.ietf.org/html/rfc3986

Slide 40

Slide 40 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. UriComponentsBuilder Boot 1.5 40 Boot 2.0 URI uri = UriComponentsBuilder.fromPath("/sample") .queryParam("q", "+hoge") .build() .encode() .toUri(); • クエリパラメータのエンコー ドはuri変数で指定して展開 時にエンコードする URI uri = UriComponentsBuilder.fromPath("/sample") .queryParam("q", "{q}") .encode() .buildAndExpand("+hoge") .toUri(); // or URI uri = UriComponentsBuilder.fromPath("/sample") .queryParam("q", "{q}") .build("+hoge");

Slide 41

Slide 41 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 4. Spring Boot起動 41 $ mvn spring-boot:run

Slide 42

Slide 42 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. Spring Boot起動の前に 42 • spring-boot-properties-migratorを⼊れよう • Boot 1.5→Boot 2.0の application.yml/propertiesの変更を⼿助けして くれるツール • Boot 1.5の書き⽅だと実⾏時にWarningを吐く • Boot 1.5の書き⽅でも動くようにしてくれる • propertiesの変更完了後このモジュールは削除する org.springframework.boot spring-boot-properties-migrator runtime

Slide 43

Slide 43 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 例: Spring Boot Actuator 43 2020-02-05 01:13:58.997 WARN 67638 --- [ main] o.s.b.c.p.m.PropertiesMigrationListener : The use of configuration keys that have been renamed was found in the environment: Property source 'applicationConfig: [classpath:/application.yml]': Key: endpoints.enabled Line: 2 Replacement: management.endpoints.enabled-by-default Key: endpoints.health.enabled Line: 4 Replacement: management.endpoint.health.enabled Each configuration key has been temporarily mapped to its replacement for your convenience. To silence this warning, please update your configuration to use the new keys. endpoints: enabled: false health: enabled: true management: endpoints: enabled-by-default: false endpoint: health: enabled: true Boot 1.5 Boot 2.0

Slide 44

Slide 44 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. コード修正振り返って 44 • Spring Data Jpa互換性なしの変更 • WebMvcConfigurerAdapter⾮推奨 • Mockito⾊々⾮推奨、変更 • spring-boot-starter-json新設 • Bean Override禁⽌ • クエリパラメータのエンコード⽅法変更 • spring-boot-properties-migrator便利

Slide 45

Slide 45 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 全体を振り返って 45 • 事前の調査と⼩さいリポジトリから対応したことにより、 ⾒積もりを⼤きく外れることはなかった • 徐々に対応することで他のタスクに⽀障はなかった • テストをしっかり書いていたので素早くエラーに気づけた • @SpringBootTestによる結合テスト⼤事 • Release NoteとMigration Guideはちゃんと読む • PRは⼩さくこまめに出す • E2Eテスト⾃動化までできると動作確認のコストを減らせ たかも

Slide 46

Slide 46 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. Copyright (C) 2019 Yahoo Japan Corporation. All Rights Reserved. ご清聴ありがとう ございました

Slide 47

Slide 47 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. Copyright (C) 2019 Yahoo Japan Corporation. All Rights Reserved. その他エラー Warning

Slide 48

Slide 48 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. Warning③ 48 $ mvn test-compile … [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo --- … [WARNING] /jsug-demo/src/test/java/com/kawakawaryuryu/boot15/demo/service/SampleServiceTest.java:[26,27] org.mockito.runnersのorg.mockito.runners.MockitoJUnitRunnerは非推奨になりました

Slide 49

Slide 49 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. MockitoJUnitRunner Boot 1.5(Mockito 1) 49 Boot 2.0(Mockito 2) import org.mockito.runners.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class SampleServiceTest { } import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class SampleServiceTest { } • org.mockito.runners.MockitoJUnitRunner がDeprecated • Mockito 3から削除

Slide 50

Slide 50 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. Warning④ 50 $ mvn test-compile … [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo --- … [WARNING] /jsug-demo/src/test/java/com/kawakawaryuryu/boot15/demo/service/SampleServiceTest.java:[10,26] org.mockitoのorg.mockito.Matchersは非推奨になりました

Slide 51

Slide 51 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. Matchers Boot 1.5(Mockito 1) 51 Boot 2.0(Mockito 2) import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.eq; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; // or import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.eq; • org.mockito.Matchers.*がDeprecated • Mockito 3から削除

Slide 52

Slide 52 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. テスト(落ちないけど吐かれる)エラー⑤ 52 • H2 Database Engine • trace.db/h2datasource.trace.db 2020-01-16 00:09:52 JDBCX: exception org.h2.jdbc.JdbcSQLException: 機能はサポートされていません: "isWrapperFor" Feature not supported: "isWrapperFor" [50100-192] at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) at org.h2.message.DbException.get(DbException.java:179) at org.h2.message.DbException.get(DbException.java:155) at org.h2.message.DbException.getUnsupportedException(DbException.java:216) at org.h2.message.TraceObject.unsupported(TraceObject.java:375) at org.h2.jdbcx.JdbcDataSource.isWrapperFor(JdbcDataSource.java:422) at org.springframework.boot.jdbc.DataSourceUnwrapper.safeUnwrap(DataSourceUnwrapper.java:77) …

Slide 53

Slide 53 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. isWrapperFor 53 • H2の1.4.197からisWrapperFor メソッドがJdbcDataSourceに追加 • Boot 2.1の依存するH2は1.4.199 Spring Boot Spring JDBC H2 1.5.14 4.3.18 1.4.193 2.1.6 5.1.8 1.4.199

Slide 54

Slide 54 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. H2をバージョンアップ Boot 1.5 54 Boot 2.1 com.h2database h2 1.4.193 com.h2database h2 1.4.199 エラー吐かれなくなった︕

Slide 55

Slide 55 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. Qiita書きました 55 • Spring Boot 2系にバージョンアップしたらH2 がエラーを吐き出したときの対処 • Spring Boot 1.5→2系バージョンアップ時の Mockito1系→2系の修正内容を取り上げてみた

Slide 56

Slide 56 text

Copyright (C) 2020 Yahoo Japan Corporation. All Rights Reserved. 参考 56 • https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0- Migration-Guide • https://github.com/spring-projects/spring-boot/wiki/spring-boot-2.0-release- notes • https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.1-Release- Notes • https://github.com/mockito/mockito/wiki/What%27s-new-in-Mockito-2 • https://docs.spring.io/spring/docs/5.0.8.BUILD-SNAPSHOT/spring-framework- reference/web.html • http://www.h2database.com/html/changelog.html