Dr. Ernst-Udo Wallenborn created CAMEL-23449:
------------------------------------------------

             Summary: Camel Spring Xml >= 4.19.0 no longer works with Spring 6
                 Key: CAMEL-23449
                 URL: https://issues.apache.org/jira/browse/CAMEL-23449
             Project: Camel
          Issue Type: Bug
          Components: camel-spring-xml
    Affects Versions: 4.20.0, 4.19.0
            Reporter: Dr. Ernst-Udo Wallenborn


With Spring version 6.2.18 and Camel 4.19.0 or newer, our application throws 
this at startup:
{noformat}
2026-05-07 13:05:43,110 ERROR 
[(:)][org.springframework.web.context.ContextLoader] Context initialization 
failed
  java.lang.NoSuchMethodError: 'org.springframework.context.ApplicationContext 
org.springframework.context.event.ContextRefreshedEvent.getSource()'
      at 
org.apache.camel.spring.xml.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:480)
      at 
org.apache.camel.spring.xml.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:99)
{noformat}
The code in CamelContextFactoryBean is:
{code:java}
        if (event.getSource() instanceof ApplicationContext) {
            ApplicationContext appCtx = (ApplicationContext) event.getSource();
{code}
 and hasn't changed significantly since 4.18.2. But running 
camel-spring-xml-4.19.0.jar through the decompiler the code changes to:
{code:java}
    if (event.getSource() instanceof ApplicationContext) {
      ApplicationContext appCtx = event.getSource();
{code}
where the typecast is removed. Apparently, Spring 7 implements getSource() in 
ApplicationContextEvent:
{code:java}
        /**
         * Get the {@link ApplicationContext} that the event was raised for.
         * @return the {@code ApplicationContext} that the event was raised for
         * @since 7.0
         * @see #getApplicationContext()
         */
        @Override
        public ApplicationContext getSource() {
                return getApplicationContext();
        }
{code}
and this covariant override causes the compiler to remove the cast.

 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to