Spring Bootのspring-boot-starter-webのデフォルトだとTomcatがサーブレットコンテナとして組み込まれますが、設定を変えればJettyに切り替えられます。
configurations { compile.exclude module: "spring-boot-starter-tomcat" } dependencies { compile("org.springframework.boot:spring-boot-starter-web:1.4.3.RELEASE") compile("org.springframework.boot:spring-boot-starter-jetty:1.4.3.RELEASE") // ... }
Tomcatを除外して、Jettyを依存関係に追加するといった手順なのですが、除外の設定はconfigurations
ではなく、dependencies
でも書けます。
dependencies { compile("org.springframework.boot:spring-boot-starter-web:1.4.3.RELEASE") { exclude module: 'spring-boot-starter-tomcat' } compile("org.springframework.boot:spring-boot-starter-jetty:1.4.3.RELEASE") // ... }
ただ、この方法では注意が必要で、他の依存関係の設定でTomcatが指定されていると、除外できていないことになります。
たとえば、下記の例だと、spring-boot-starter-thymeleaf
がspring-boot-starter-web
に依存しているので、そこからのルートでTomcatを引き込んでしまいます。
dependencies { compile("org.springframework.boot:spring-boot-starter-web:1.4.3.RELEASE") { exclude module: 'spring-boot-starter-tomcat' } compile("org.springframework.boot:spring-boot-starter-jetty:1.4.3.RELEASE") compile('org.springframework.boot:spring-boot-starter-thymeleaf') // ... }
なので、除外するときには、Springの公式サイトにあるとおり、configurations
で書いたほうが確実です。
どのような依存関係になっているかは、dependencies
タスクで確認できますので、そちらで意図した形になっているか確認してみるのが良いかと思います。