I am desperately trying to use application.yml property inside @EventListener condition and I can't find a solution anywhere, I dug as far as spring forums to 2010 and endless stackoverflow questions, which I only encountered one being mentioned with no reply and suggestion to use a config bean which is just a workaround and hard to use:

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = TestEventListenerTest.TestConfig.class, initializers = ConfigFileApplicationContextInitializer.class)
@TestPropertySource(properties = {"bla.number=123"})
@EnableConfigurationProperties(TestConfigProperties.class)

This condition should work but it doesn't:

@EventListener(classes = SomeEvent.class, condition = "event.payload.number == ${bla.number}")
        public void listen(SomeEvent someEvent) {
            interactee.interact();
        }

${} - trying to reference like in @Value results in:

EL1041E: After parsing a valid expression, there is still more data in the expression: 'lcurly({)'

Comment From: antonalechnovic

Ugly Workaround: managed to load the @ConfigurationProperties bean into condition finally after inspecting beanfactory names, but it is quite long, as autogen name comprises of full property path and full package name. If I could just use ${bla.number} inside condition of @EventListener this would be much better. Also if we have a single @Value which we would not create config properties class for, then there is no way to achieve this at all.

@EventListener(classes = SomeEvent.class, condition = "event.payload.phoneNumber.number == @'bla.number-package.package.package.package.package.package.TestConfigProperties'.number")

Comment From: sbrannen

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

Comment From: antonalechnovic

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

This is nothing to do with stackoverflow, it is impossible to reference property inside @EventListener without bean , why close? I've updated the title and all posts with the expectation. SpEL is half broken inside "condition". Please remove the so tag and reopen the issue.

Comment From: cwdesautels

@sbrannen @antonalechnovic This definitely feels like a missing feature in spel evaluation. For reference there is a work-around in a related StackOverflow post (see below), we should not have to invoke functions to indirectly access properties.

https://stackoverflow.com/questions/50723383/evaluate-property-from-properties-file-in-springs-eventlistenercondition