Using @EnabledIf with spring.profiles.active property in Spring Environment within tests

前端 未结 3 1031
死守一世寂寞
死守一世寂寞 2021-02-06 11:08

According to the documentation (https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/context/junit/jupiter/EnabledIf.html#expression--) you

相关标签:
3条回答
  • 2021-02-06 12:04

    Try that with an extra apostrophe to wrap property when used in SpEL:

    @EnabledIf(value = "#{'${spring.profiles.active}' == 'test'}", loadContext = true)
    

    I worked for me (finally!) when I tried to use custom property

    0 讨论(0)
  • 2021-02-06 12:06

    To check the exact value of a property from the Spring Environment, you should use the following approach.

    @EnabledIf(expression = "#{environment['spring.profiles.active'] == 'test'}", loadContext = true)
    

    To check which profiles are currently active in the Spring Environment, you should use the following approach.

    @EnabledIf(expression = "#{environment.acceptsProfiles('test', 'someotherprofile')}", loadContext = true)
    
    0 讨论(0)
  • 2021-02-06 12:06

    Your expression should look like this:

    @EnabledIf(value = "${spring.profiles.active == 'test'}", loadContext = true)
    
    0 讨论(0)
提交回复
热议问题