Using @Profile annotation with property place holder value

前端 未结 3 1746
挽巷
挽巷 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 17:55

    You seem to be trying to abuse the @Profile annotation. Use profiles for enabling functionality. Not for saying that a Bean is active in a specific environment.

    A way to achieve something closer to what I think you are looking for, would be to have properties files specific to your environment, which define the profiles which should be active in them. This way, you can start your app with an arg such as:

    --spring.profiles.active=prd
    

    Spring Boot will then attempt to load application-prd.properties, where you could activate environment-specific profiles:

    spring.profiles.active=sqlserver,activedirectory,exchangeemail
    

    That way your beans will only be activated when the functionality they provide is required.

提交回复
热议问题