I'm guessing something is wrong integrating my spring and camel contexts.
I'm unit testing a Camel Component, and I'm trying to inject a bean (MainframeEncoderProvider) generated by spring component-scan. I can see that the bean is being constructed (breakpointing an init block), and I can autowire it into ToFalinkProducerTest, but it's not getting into the camel Component. The component is instantiated via META-INF auto-discovery, if that's relevant (http://camel.apache.org/how-do-i-add-a-component.html)
Test class setup:
@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>
component:
/**
* 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;
}
}
ToFalinkComponenta spring bean? - pvpkiran