afnf.net

Spring MVCからSpring Bootに移行した

このブログですが、Spring MVC 4.1からSpring Boot 1.2.3に移行しました。

blog-java1 (Spring MVC 4.1+Jetty 9.1)

https://github.com/af-not-found/blog-java1

blog-java2 (Spring Boot 1.2.3+Embedded Tomcat)

https://github.com/af-not-found/blog-java2


移行にあたって移植が必要だったのは、主に以下3点でした。

設定ファイルをJava Configに移行

全体的にスッキリしました。

JSPをThymeleafに書き換え

これは時間がかかりました。でもThymeleaf使いやすくて良いですね。

JSPの自作ELファンクションは、ThymeleafのDialectとしてほとんどそのまま使えました。JSPのTLDファイルが、ThymeleafConfig.javaに置き換わった形です。

Maven+Selenium+JaCoCoによるテスト

以前のエントリで、jetty-maven-pluginを使ったSelenium統合テストとカバレッジ計測方法を紹介しました。

Spring Bootでも同様に、単体テスト・統合テストのカバレッジ計測が実施できます。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>-Dspring.profiles.active=${spring.profiles.active} ${jacocoArgs}</argLine>
  </configuration>
</plugin>

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <configuration>
    <argLine>-Dspring.profiles.active=${spring.profiles.active} ${jacocoArgs}</argLine>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>integration-test</goal>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.apache.maven.surefire</groupId>
      <artifactId>surefire-junit47</artifactId>
      <version>2.18</version>
    </dependency>
  </dependencies>
</plugin>

ポイントはargLine${jacocoArgs}だけです。

jetty-maven-pluginに該当するものが必要なくなったため、かなりスッキリしました。組み込みTomcatの大きな利点です。

その他

逆に、これ以外はほとんど書き換えていません。Serviceクラスとか、SQLとか、Seleniumテストケースも。

Spring Boot良いですね。気に入りました。

comments (0)

blog-java2 engine (build:2019-02-23 17:57 JST)