かんがるーさんの日記

最近自分が興味をもったものを調べた時の手順等を書いています。今は Spring Boot をいじっています。

共有ライブラリを管理するために Sonatype の Nexus Repository Manager OSS を使用する ( その21 )( Spring Framework に依存するライブラリを作成する4 )

概要

共有ライブラリを管理するために Sonatype の Nexus Repository Manager OSS を使用する ( その20 )( Spring Framework に依存するライブラリを作成する3 ) の続きです。

  • 今回の手順で確認できるのは以下の内容です。
    • ksbysample-webapp-demo プロジェクトに ksbysample-library-depend-spring ライブラリを導入して動作確認します。
    • ksbysample-library-depend-spring ライブラリを導入するだけで、@RequestMapping アノテーションで定義した URL にアクセスすれば request, response のデータのログが出力されるようになるはずです。

参照したサイト・書籍

目次

  1. ksbysample-webapp-demo プロジェクトに ksbysample-library-depend-spring ライブラリを導入する
  2. 動作確認する
  3. 1.3.6 ベースの ksbysample-webapp-demo プロジェクトに 1.3.8 ベースの ksbysample-library-depend-spring ライブラリを導入すると Spring Boot はどのバージョンが使用されるのか?
  4. 次回は。。。

手順

ksbysample-webapp-demo プロジェクトに ksbysample-library-depend-spring ライブラリを導入する

  1. build.gradle を リンク先の内容 に変更します。変更後、Gradle projects View の左上にある「Refresh all Gradle projects」ボタンをクリックして反映します。

動作確認する

  1. Gradle projects View から bootRun タスクを実行し、Tomcat を起動します。

  2. ブラウザを起動し http://localhost:8080/sample にアクセスすると、request, response のログが出力されることが確認できました。

    f:id:ksby:20161227014628p:plain

Spring Boot の Auto-configuration を初めて使ってみましたが、AOP の処理も共通ライブラリ化できるのは結構便利な気がします。

1.3.6 ベースの ksbysample-webapp-demo プロジェクトに 1.3.8 ベースの ksbysample-library-depend-spring ライブラリを導入すると Spring Boot はどのバージョンが使用されるのか?

コマンドプロンプトを起動しカレントディレクトリを c:\project-springboot\ksbysample-nexus-repomng\ksbysample-webapp-demo へ移動した後、gradlew dependencies コマンドを実行すると以下の内容が出力されました。

一番下に ksbysample-library-depend-spring の依存関係が出力されていますが、org.springframework.boot:spring-boot-starter-web:1.3.8.RELEASE -> 1.3.6.RELEASE (*) のように 1.3.6 にダウングレードしていました。ライブラリではなくプロジェクトのバージョンが使用されるのでしょうか。。。

compile - Dependencies for source set 'main'.
+--- org.springframework.boot:spring-boot-starter-web: -> 1.3.6.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:1.3.6.RELEASE
|    |    +--- org.springframework.boot:spring-boot:1.3.6.RELEASE
|    |    |    +--- org.springframework:spring-core:4.2.7.RELEASE
|    |    |    \--- org.springframework:spring-context:4.2.7.RELEASE
|    |    |         +--- org.springframework:spring-aop:4.2.7.RELEASE
|    |    |         |    +--- aopalliance:aopalliance:1.0
|    |    |         |    +--- org.springframework:spring-beans:4.2.7.RELEASE
|    |    |         |    |    \--- org.springframework:spring-core:4.2.7.RELEASE
|    |    |         |    \--- org.springframework:spring-core:4.2.7.RELEASE
|    |    |         +--- org.springframework:spring-beans:4.2.7.RELEASE (*)
|    |    |         +--- org.springframework:spring-core:4.2.7.RELEASE
|    |    |         \--- org.springframework:spring-expression:4.2.7.RELEASE
|    |    |              \--- org.springframework:spring-core:4.2.7.RELEASE
|    |    +--- org.springframework.boot:spring-boot-autoconfigure:1.3.6.RELEASE
|    |    |    \--- org.springframework.boot:spring-boot:1.3.6.RELEASE (*)
|    |    +--- org.springframework.boot:spring-boot-starter-logging:1.3.6.RELEASE
|    |    |    +--- ch.qos.logback:logback-classic:1.1.7
|    |    |    |    +--- ch.qos.logback:logback-core:1.1.7
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.20 -> 1.7.21
|    |    |    +--- org.slf4j:jcl-over-slf4j:1.7.21
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.21
|    |    |    +--- org.slf4j:jul-to-slf4j:1.7.21
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.21
|    |    |    \--- org.slf4j:log4j-over-slf4j:1.7.21
|    |    |         \--- org.slf4j:slf4j-api:1.7.21
|    |    +--- org.springframework:spring-core:4.2.7.RELEASE
|    |    \--- org.yaml:snakeyaml:1.16
|    +--- org.springframework.boot:spring-boot-starter-tomcat:1.3.6.RELEASE
|    |    +--- org.apache.tomcat.embed:tomcat-embed-core:8.0.36
|    |    +--- org.apache.tomcat.embed:tomcat-embed-el:8.0.36
|    |    +--- org.apache.tomcat.embed:tomcat-embed-logging-juli:8.0.36
|    |    \--- org.apache.tomcat.embed:tomcat-embed-websocket:8.0.36
|    |         \--- org.apache.tomcat.embed:tomcat-embed-core:8.0.36
|    +--- org.springframework.boot:spring-boot-starter-validation:1.3.6.RELEASE
|    |    +--- org.springframework.boot:spring-boot-starter:1.3.6.RELEASE (*)
|    |    +--- org.apache.tomcat.embed:tomcat-embed-el:8.0.36
|    |    \--- org.hibernate:hibernate-validator:5.2.4.Final
|    |         +--- javax.validation:validation-api:1.1.0.Final
|    |         +--- org.jboss.logging:jboss-logging:3.2.1.Final -> 3.3.0.Final
|    |         \--- com.fasterxml:classmate:1.1.0
|    +--- com.fasterxml.jackson.core:jackson-databind:2.6.7
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.6.0 -> 2.6.7
|    |    \--- com.fasterxml.jackson.core:jackson-core:2.6.7
|    +--- org.springframework:spring-web:4.2.7.RELEASE
|    |    +--- org.springframework:spring-aop:4.2.7.RELEASE (*)
|    |    +--- org.springframework:spring-beans:4.2.7.RELEASE (*)
|    |    +--- org.springframework:spring-context:4.2.7.RELEASE (*)
|    |    \--- org.springframework:spring-core:4.2.7.RELEASE
|    \--- org.springframework:spring-webmvc:4.2.7.RELEASE
|         +--- org.springframework:spring-beans:4.2.7.RELEASE (*)
|         +--- org.springframework:spring-context:4.2.7.RELEASE (*)
|         +--- org.springframework:spring-core:4.2.7.RELEASE
|         +--- org.springframework:spring-expression:4.2.7.RELEASE (*)
|         \--- org.springframework:spring-web:4.2.7.RELEASE (*)
+--- ksbysample.library:ksbysample-library-simpleutils:1.0-RELEASE
+--- ksbysample.library:ksbysample-library-depend-nospring:1.1-RELEASE
|    \--- org.apache.commons:commons-lang3:3.4 -> 3.5
\--- ksbysample.library:ksbysample-library-depend-spring:1.0.0-RELEASE
     +--- org.springframework.boot:spring-boot-autoconfigure:1.3.8.RELEASE -> 1.3.6.RELEASE (*)
     +--- org.springframework.boot:spring-boot-starter-web:1.3.8.RELEASE -> 1.3.6.RELEASE (*)
     +--- org.aspectj:aspectjweaver:1.8.9
     +--- org.apache.commons:commons-lang3:3.5
     \--- com.google.guava:guava:20.0

.....(本当はもっと出力されています)....

次回は。。。

次の2点を試してみます。

  • 1.4 系のプロジェクトに 1.3.8 ベースの ksbysample-library-depend-spring ライブラリを導入すると Spring Boot はどのバージョンが使用されるのか、に興味が湧いたのでちょっと試してみます。
  • ksbysample-library-depend-spring を導入してもデフォルトでは動作せず、ksbysample.library.request-and-response-logger.enabled=true を設定した時だけ動作するようにできるか試してみます。

ソースコード

build.gradle

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test')

    compile('ksbysample.library:ksbysample-library-simpleutils:1.0-RELEASE')
    compile('ksbysample.library:ksbysample-library-depend-nospring:1.1-RELEASE')
    compile('ksbysample.library:ksbysample-library-depend-spring:1.0.0-RELEASE')
}
  • dependencies に compile('ksbysample.library:ksbysample-library-depend-spring:1.0.0-RELEASE') を追加します。

履歴

2016/12/27
初版発行。