私のSpringとCamelのコンテキストを統合するのが間違っていると思います。springコンポーネントをcamelコンポーネントにオートワイヤーできないコンポーネント
私はキャメルコンポーネントをテストしていますが、私はスプリングコンポーネントスキャンによって生成された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です。 – pvpkiran
わかりません。自動検出設定に関する私のコメントを参照してください。これは、その条件が満たされているか、別のプロセスであるかわかりません。 – NielsR
SpringがビルドするようにToFalinkComponentに@Component(value = "tofalink")を付けると、このコンポーネントの自動ディスカバリが削除され、プロバイダはAutowiredではなく、Camelはエンドポイントを作成するコンポーネントを見つけることができません。 – NielsR