0
我猜猜我的春天和駱駝上下文有什麼不對。無法自動連接彈簧組件到駱駝組件
我正在測試一個Camel組件,我試圖注入一個由Spring組件掃描生成的bean(MainframeEncoderProvider)。我可以看到這個bean正在構建中(突出一個init塊),並且我可以將它自動裝入到ToFalinkProducerTest中,但它沒有進入駱駝組件。該組件是通過META-INF自動發現實例化的,如果這是相關的(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;
}
}
這是'ToFalinkComponent'一個spring bean嗎? – pvpkiran
不確定。看到我對自動發現設置的評論,我不知道這是否符合要求或是一個單獨的過程。 – NielsR
如果我刪除了此組件的自動發現,並使用@Component(value =「tofalink」)註釋ToFalinkComponent,以便Spring構建它,那麼提供程序仍然不是Autowired,並且Camel無法找到創建Endpoint的組件。 – NielsR