java - Spring Boot Configuration Processor, Duplicate @ConfigurationProperties definition for prefix -


in spring boot application, want use @configurationproperties annotation same prefix configure 2 data sources depending profile. why forbidden spring boot configuration processor ? error reported gradle is:

... :compilejava ... error: duplicate `@configurationproperties` definition prefix 'spring.datasource' 

notes:

  • "run as->spring boot app" works in sts
  • without spring-boot-configuration-processor dependency, gradle build works (but warning when using @configurationproperties recommended add 'spring-boot-configuration-processor' classpath generate configuration metadata appears)

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

@springbootapplication public class application {      public static void main(final string[] args) {         final springapplication app = new springapplication(application.class);         app.setadditionalprofiles("prod");         app.run();     }      @bean     @profile("dev")     @configurationproperties("spring.datasource")     public datasource datasourcedev() {         return datasourcebuilder                 .create()                 .url(generatedevurl())                 .build();     }      @bean     @profile("prod")     @configurationproperties("spring.datasource")     public datasource datasourceprod() {         return datasourcebuilder                 .create()                 .url(generateprodurl())                 .build();     }  } 

thanks in advance

i think confused on how works. code should stay same. properties change when define profile load @ start up.

application-dev.properties

spring.datasource.driverclassname = org.h2.driver 

spring.datasource.username = sa spring.datasource.password = sa spring.datasource.url=

appilication-prod.properties

spring.datasource.driverclassname = org.h2.driver spring.datasource.username = sa spring.datasource.password = sa spring.datasource.url=

and 1 bean setup datasource.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -