Using @Profile annotation with property place holder value

前端 未结 3 1781
挽巷
挽巷 2021-01-18 17:37

When we define profile for any component in spring, we declare it as @Profile(value=\"Prod\"). But i want to give that value from properties file. Is it possibl

3条回答
  •  青春惊慌失措
    2021-01-18 18:13

    An alternative would be when creating the ApplicationContext:

    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConfigClass.class);
    String profile = aplicationContext.getEnvironemnt().getRequiredProperty("profile");
    applicationContext.getEnvironment().setActiveProfiles(profile);
    

提交回复
热议问题