spring-boot: Configuration Processor @Bean Duplicate Prefix Definition APT Error
When using the spring-boot-configuration-processor and leveraging the same @ConfigurationProperties prefix on an @Bean I am seeing an APT error in Eclipse in 1.4.0.RELEASE. While I agree that this error should be generated when using a duplicate prefix on an @Component class definition, I think this restriction should be relaxed on @Bean definitions.
I am referencing the External Config 3rd Party Configuration section in the reference guide.
Basic example of the issue
@Bean
@ConfigurationProperties("spring.datasource.tomcat")
public DataSource readDataSource() {
return DataSourceBuilder.create()
.url(properties.getReadUrl())
.username(properties.getUsername())
.password(properties.getPassword())
.build();
}
@Bean
@ConfigurationProperties("spring.datasource.tomcat")
public DataSource readWriteDataSource() {
return DataSourceBuilder.create()
.url(properties.getReadUrl())
.username(properties.getUsername())
.password(properties.getPassword())
.build();
}
Duplicate `@ConfigurationProperties` definition for prefix 'spring.datasource.tomcat'.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 2
- Comments: 15 (8 by maintainers)
我觉得楼主说的挺对的,
@ConfigurationProperties注解本身的作用就是将特定的配置属性应用到某个springbean中,从这一点来讲,此注解本身不应该限定其prefix是否重复。 我当前遇到的问题就是,当我使用springboot配置多数据源时,我需要将hikari的相关配合应用到所有的数据源上,而且我希望所有数据源共享这些配置,因此我在每个数据源上都使用了@ConfigurationProperties("spring.datasource.hikari")这样的注解,然而springboot确提示我重复使用了@ConfigurationProperties,即使我将这两个注解写在了不同的类中 希望springboot官方能看到此issue,并修正此问题Courtesy of Google translate
@sxyandapp A meta-data entry is related to a group and a group is related to a source. If we’d allowed this, you’d get the same keys duplicated over and over again (which matches your situation). You want the exact opposite (a single key that configures multiple groups). I’d rather have dedicated namespace (so that you can fine tune thing individually) and an
EnvironmentPostProcessorthat can map a “main namespace”@wuwen5, I’d combine the two
@Beanmethods into one and use theEnvironmentto check the value of thespring.datasource.hikari.refreshproperty and then set the Hikari system property as needed. If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.