0
我想从应用程序中的属性文件激活配置文件。最后,我要动态激活配置文件,但我想先从静态我可以在Spring Boot中激活@PropertySource文件中的配置文件吗?
我的应用程序
@SpringBootApplication @PropertySource("classpath:/my.properties")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Component public static class MyBean {
@Autowired public void display(@Value("${abc}") String abc) {
System.out.println("Post:"+ abc);
}
my.properties:
spring.profiles.active=STAT
abc=ABC
我的输出是一个证明,my.properties读,但配置文件被忽略
没有活动配置文件集,回落到默认配置文件:默认
显示:ABC
也许我应该解释一下我想达到的目标。我的Spring之前的启动应用程序行为取决于环境,例如,如果$ENV=DEV
使用开发配置。我想迁移到Spring引导并将配置文件放到配置文件中,但我希望保持环境不变。 我想实现一个
if $ENV=DEV then profile DEV is selected
我的想法是添加my.properties
与spring.profiles.active=$ENV
,但它不工作