LoginSignup
2
3

More than 5 years have passed since last update.

Spring Boot 1.5 から 2.1 に移行した時にハマったこと

Posted at

SpringBoot 1.5 のサポートが2019年8月1日に終了するので移行しようとしたらすごくハマったので共有したい。

Lombokでコンパイルができない

Lombbokが生成してくれるはずのメソッドやプロパティが見つからない場合はこれ。

  • getter/setterがない
  • @AllArgsConstructorつけてる場合はコンストラクタがない
  • @Slf4jつけてる場合はlogがない
  • ...etc
対策

gradleの5.x系ではLombokのコンパイルができない。
4.x系にダウングレードする。

gradle-wrapper.properties
# distributionUrl=https\://services.gradle.org/distributions/gradle-5.2-rc-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip

Mainファイルが無いよって怒られる

Main class name has not been configured and it could not be resolved

マルチモジュールプロジェクトだとよく発生するかも。
build.gradleapply plugin: 'org.springframework.boot'を書いてると発生。

対策

実行可能jarにしたいモジュールのbuild.gradleにだけ書いてあげる。

実行可能にしなくてよいmodule

build.gradle
// apply plugin: 'org.springframework.boot'

実行可能jarのmodule

build.gradle
apply plugin: 'org.springframework.boot'

// なくなりました
//springBoot {
//  executable = true
//}

// 代わりにこっち
bootJar {
    launchScript()
}

起動時にLogbackの設定でエラー

ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not create an Appender of type [org.springframework.boot.logging.logback.LevelRemappingAppender]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type org.springframework.boot.logging.logback.LevelRemappingAppender

LevelRemappingAppenderがなくなったらしい。
ログのノイズを抑えるために、ERRORレベルからWARNに変えたりするアダプターのようです。

対策

LevelRemappingAppenderで検索してアダプター設定を削除する。
代替アダプターを探したが見つけられなかった。
ログのノイズ抑えるものであって、アプリケーションの動きに変わりはないので削除しても問題ないはず。

logback.xml
<!--<appender name="DEBUG_LEVEL_REMAPPER" class="org.springframework.boot.logging.logback.LevelRemappingAppender">-->
    <!--<destinationLogger>org.springframework.boot</destinationLogger>-->
<!--</appender>-->

Sessionにhash_mapを指定してエラー

ローカル開発環境やテスト時に使用していたhash_mapがなくなりました。

対策

storetype=noneにして@ConcurrentHashMapのBeanを生成する

SpringHttpSessionConfig.java
@EnableSpringHttpSession
@Configuration
public class SpringHttpSessionConfig {
  @Bean
  public MapSessionRepository sessionRepository() {
    return new MapSessionRepository(new ConcurrentHashMap<>());
  }
}

ただし、本番環境ではRedisを使っていて切り替える必要がある場合は上記のコードでは上手くいかなかった。
Dockerで簡単にRedis立ち上げられるので、最初からhash_map使わずに、Redisで開発するのが良いと思う。

Thymeleafの属性指定でエラー

Thymeleaf2→3になった影響で書き方が変わった。

before

<a href="#" th:onclick="'changeLocation(\'' + ${id} + '\');'" />

after

<a href="#" th:attr="onclick='changeLocation(' + ${id} + ');'" />

さいごに

上記以外にも色々ハマってます。(現在進行系)
順次追記していこうと思います。

2
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3