配置环境
spring.profiles.active=dev
获取当前环境
方法一
通过@Value注解获取
@Value("${spring.profiles.active}")
private String env;
方法二
在配置文件中通过environment判断
@Bean
public Docket docket(Environment environment) {
System.out.println(Arrays.asList(environment.getActiveProfiles()).contains("dev"));
}
方法三
判断多个环境
@Bean
public Docket docket(Environment environment) {
Profiles profiles=Profiles.of("dev","test");
boolean enable=environment.acceptsProfiles(profiles);
}
标签:Java,环境,dev,environment,获取,profiles,当前
From: https://www.cnblogs.com/Bin-x/p/16853235.html