骆驼路线无法在xml文件中解析

时间:2019-12-13 10:25:59

标签: java apache-camel java-11 spring5

我正在从Java 8升级到Java 11。 甚至以前使用的Spring版本是4.x,现在我已经升级到Spring 5.x

我在路上骑骆驼

我的骆驼上下文文件如下

 <bean id="samplePriceBean"
    class="com.abc.SamplePriceBean">
    <constructor-arg index="0"
        ref="route1" />
        <constructor-arg index="1"
        ref="route2" />
    <constructor-arg index="2"
        ref="myCamelContext" />
    <constructor-arg index="3" value="route1" />
    <constructor-arg index="4" value="route1" />
</bean>
<camelContext id="myCamelContext" xmlns="http://camel.apache.org/schema/spring">
    <route id="listRoute" autoStartup="false">
        <from
            uri="file:{{abc.list}}?noop=true&amp;" />
        <to uri="direct:route1"
            id="route1" />
    </route>
    <route id="readRoute" autoStartup="false">
        <from
            uri="file:{{abc.read}}?noop=true&amp;" />
        <to uri="direct:route2"
            id="route2" />
    </route>
</camelContext>

现在,当我在控制台中按如下所示运行应用程序错误时

Error creating bean with name 'samplePriceBean' defined in class path resource [app-camel.xml]: Cannot resolve reference to bean 'route1' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'route1' available
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:787)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

应用程序无法解析在骆驼上下文中定义的路由

我正在使用JDk 11,SPring 5.x,Apache camel 3.0.0

2 个答案:

答案 0 :(得分:1)

好的,所以从一开始这也是错误的

        

<route>用于定义路由,并且路由未公开为spring依赖注入可以使用/查找的spring bean。仅<camelContext>就是它的CamelContext

在您的SamplePriceBean中,您可以更改其构造函数以不将route1和route2用作参考,但是您可以使用CamelContext中的API通过CamelContext API查找这些路由(不是Spring bean ID)。

答案 1 :(得分:0)

Camel 2.x不支持Java11。您应该将Camel 3用于Java 11支持。