79547812

Date: 2025-04-01 06:01:47
Score: 2
Natty:
Report link

@ConditionalOnExpression can be used in this way to achieve condition X or condition Y but not both. I tested this code with the same application.yaml provided.

    @Bean
    @ConditionalOnExpression("#{('${app.config.inside.prop}' == 'a' && '${app.config.outside.prop}' != 'a') || ('${app.config.inside.prop}' != 'a' && '${app.config.outside.prop}' == 'a')}")
    public CustomBean customInsideOrOutsideNotBoth() {
        System.out.println("app.config.inside _or_ app.config.outside _not_ both");
        return new CustomBean();
    }
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @ConditionalOnExpression
  • Looks like a comment (1):
  • Low reputation (1):
Posted by: Hdvlp