Skip to content

PropertySources

指定@ConfigurationProperties 注解中所使用的配置信息是从当前类路径下的 application.properties 配置文件中进行读取

java
@Component
@ConfigurationProperties(prefix = "diyai.wx")
@PropertySource(value = "classpath:wxConfig.properties")
public class WxConfig {

也可以引入多个配置文件 @PropertySources

java
@Component
@PropertySources({
        @PropertySource("classpath:wxConfig.properties"),
        @PropertySource("classpath:mpConfig.properties")
})
public class WxConfig {

启动 wxserver-0.0.1.jar 时加载D盘下的 application.properties 文件,以及位于当前类路径下 config 目录中的所有配置文件:

shell
java -jar wxserver-0.0.1.jar --spring.config.location=file:///D:/deploy/application.properties, classpath:/config/