Springブートアプリケーションでは、同じプレフィックスを持つ@ConfigurationProperties
注釈を使用して、プロファイルに応じて2つのデータソースを設定します。なぜそれはSpringブート設定プロセッサによって禁止されていますか? Gradleので報告されたエラーは次のとおりです。スプリングブートコンフィギュレーションプロセッサ、プレフィックスの@ConfigurationProperties定義の重複
...
:compileJava ... error: Duplicate `@ConfigurationProperties` definition for prefix 'spring.datasource'
注:
- "ファイル名を指定して実行AS->春ブーツのAppは、" 春・ブート・コンフィギュレーション・プロセッサ依存性がないとSTS
- で動作し、Gradleのビルド作品(ただし、警告
When using @ConfigurationProperties it is recommended to add 'spring-boot-configuration-processor' to your classpath to generate configuration metadata
が表示されます)
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.6.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
repositories {
mavenCentral()
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile 'org.springframework.boot:spring-boot-configuration-processor:1.5.4.RELEASE'
compile("com.h2database:h2")
}
application.properties
spring.datasource.driverClassName = org.h2.Driver
spring.datasource.username = sa
spring.datasource.password = sa
hello.Application事前
これらの豆はまったく同じですが、なぜその設定が必要なのでしょうか? –
私のプロダクションコードはもっと複雑です。私はそれをあまりにも単純化しました。サンプルコードを更新しました。 – cmaulini
それでも、やってはいけないことをやっているように見えます。なぜこれが必要ですか?主な問題点は、URLを生成するさまざまな方法があることです。しかし、それはあなたがコードではなくconfigであるべきである。 –