SpringBoot multi-module uses ConfigurationProperties annotations, why only one module can be used?

  • the current project is divided into multiple sub-modules using maven.
  • each submodule has a corresponding configuration file, which is configured using ConfigurationProperties annotations.

my pom file in the main project looks like this

<dependency>
    <groupId>com.shopping.framework</groupId>
    <artifactId>spring-boot-starter-pay</artifactId>
    <version>1.0.0.RELEASE</version>
</dependency>

<!--  -->
<dependency>
    <groupId>com.shopping.framework</groupId>
    <artifactId>spring-boot-starter-sms</artifactId>
    <version>1.0.0.RELEASE</version>
</dependency>

the problem now is:
the ConfigurationProperties configuration of the spring-boot-starter-pay module takes effect, and the other annotation is invalid. When starting, the breakpoint of the set method will not be entered. If I change the order, it will be the reverse, spring-boot-starter-sms will take effect, and the pay module will not take effect.
excuse me, does ConfigurationProperties only support one class file?

Jul.26,2021

@ Yujiaao is indeed the reason. Thank you very much for your reminder. The final solution is to customize a configuration file for each module, whose name must be different from that of other modules, and then annotate the configuration class to specify the profile name: @ PropertySource ("classpath:sms.properties")

Menu