首页 文章

无法将spring组件自动装配到camel组件中

提问于
浏览
0

我猜测整合我的 Spring 天和骆驼情境有些不对劲 .

我试图注入一个由spring component-scan生成的bean(MainframeEncoderProvider) . 我可以看到bean正在被构造(打破一个init块),我可以将它自动装入ToFalinkProducerTest,但是's not getting into the camel Component. The component is instantiated via META-INF auto-discovery, if that'是相关的(http://camel.apache.org/how-do-i-add-a-component.html

测试类设置:

@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:spring-config/testContext.xml"})
public class ToFalinkProducerTest extends CamelTestSupport{

[some tests...]

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() {
            //@formatter:off

            from("direct:start")
                    .to("tofalink:x?encoderName=test")
                    .to("mock:result");
            //@formatter:on
        }
    };
}

的TestContext:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd

        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd

        http://camel.apache.org/schema/spring
        http://camel.apache.org/schema/spring/camel-spring.xsd
        ">

    <!-- lightweight testcontext -->
    <context:annotation-config/>
    <context:component-scan base-package="net.mo"/>

    <camel:camelContext>
            <camel:contextScan/>
    </camel:camelContext>


</beans>

零件:

/**
 * Represents the component that manages {@link ToFalinkEndpoint}.
 */
public class ToFalinkComponent extends DefaultComponent {

    @Autowired
    private MainframeEncoderProvider provider;

    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
        Endpoint endpoint = new ToFalinkEndpoint(uri, this);
        setProperties(endpoint, parameters);
        return endpoint;
    }

    protected MainframeEncoderProvider getProvider() {
        return this.provider;
    }
}

1 回答

  • 0

    经过大量的调整后,管理来解决这个问题 . 用CamelSpringTestSupport替换了CamelTestSupport扩展,并删除了@RunWith和@ContextConfiguration . 使用我的xml spring上下文文件实现createApplicationContext(),以保留组件扫描 .

    离开了自动发现机制 .

    现在我只需看看它是否在运行时工作:/

相关问题