【发布时间】:2017-05-18 12:02:33
【问题描述】:
当我使用命令时
mvn spring-boot:run -Dspring.profiles.active=web
我的项目正在运行,但@Profile("web") bean 代码未使用,仅使用
bean 编写的属性
@Profile("default")
如何更改它,并将属性更改为网络配置文件?
@Profile("default")
@Bean
static public PropertySourcesPlaceholderConfigurer defaultPropertySourcesPlaceholderConfigurer() {
PropertySourcesPlaceholderConfigurer p = new PropertySourcesPlaceholderConfigurer();
Resource[] resourceLocations = new Resource[] { new ClassPathResource("job.core.properties") };
p.setLocations(resourceLocations);
return p;
}
@Profile("web")
@Bean
static public PropertySourcesPlaceholderConfigurer prodWebPropertySourcesPlaceholderConfigurer() {
PropertySourcesPlaceholderConfigurer p = new PropertySourcesPlaceholderConfigurer();
Resource[] resourceLocations = new Resource[] {new ClassPathResource("job.core.ris.properties") };
p.setLocations(resourceLocations);
return p;
}
job.core.ris.properties
db.driverClass=com.mysql.jdbc.Driver
db.jdbcUrl=jdbc:mysql://192.168.0.68:3306/job_ris?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=UTF-8
db.user=root
db.password=
job.core.properties
db.driverClass=com.mysql.jdbc.Driver
db.jdbcUrl=jdbc:mysql://192.168.0.68:3306/dev?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=UTF-8
【问题讨论】:
-
为什么
@Bean注解的方法是静态的?尝试删除static -
如果删除静态 jdbcUrl 将为空
标签: spring maven spring-boot profiles