0
点赞
收藏
分享

微信扫一扫

springboot获取profile的方法

ZGtheGreat 2022-04-26 阅读 73
java后端

通过代码获取profile

@Component
public class ProfileUtils implements ApplicationContextAware {

private static ApplicationContext context = null;

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.context = applicationContext;
}

public static String getActiveProfile(){
    String[] profiles = context.getEnvironment().getActiveProfiles();
    if(profiles.length != 0){
        return profiles[0];
    }
    return "";
}
}

通过注解的方式来获取Profile

@Profile("dev","test")
//下面的配置信息只有在dev环境和test环境会生效
@Service
举报

相关推荐

0 条评论