通过代码获取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.getEnviroment().getActiveProfiles();

if(profiles.length != 0){

return profiles[0];

}

return "";

}

}

通过注解的方式来获取Profile


@Profile("dev","test")

//下面的配置信息只有在dev环境和test环境会生效

@Service

投票

作为一个开发者,你更喜欢那种方式来使用profile呢?