camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: CamelSpringTestSupport and support for @Autowired/@Inject
Date Wed, 11 May 2011 14:45:29 GMT
On Wed, May 11, 2011 at 4:48 AM, Willem Jiang <willem.jiang@gmail.com> wrote:
> Oh, CamelSpringTestSupport doesn't support @Autowired annotation.
> That annotation is part of Spring test framework, you need to extends your
> test with the Spring test one.
>

I would assume springs bean post processor runs as well which does the
@Autowired stuff.
However for that to work you may have to enable that
<context:annotation-config/> in your spring xml file.

See the spring docu
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-annotation-config


> On 5/10/11 4:25 PM, Xavier Coulon wrote:
>>
>> Hello,
>>
>> I'm running into a NullPointerException in my test case below:
>>
>> public class MyActivityMonitorTestCase
>> extends CamelSpringTestSupport {
>>
>> @Autowired
>> private MyActivityMonitor activityMonitor;
>>
>> @EndpointInject(uri = "mock:mock")
>> private MockEndpoint mockEndpoint;
>>
>> @Override
>> protected AbstractApplicationContext createApplicationContext() {
>> return new ClassPathXmlApplicationContext(new String[] {
>> "classpath*:/META-INF/spring/applicationContext-xyz1.xml",
>> "classpath:/META-INF/spring/applicationContext-xyz2.xml" });
>> }
>>
>> }
>>
>> The bean named 'activityMonitor' is created within the Spring Application
>> context, but it is not injected in the test case, because I'm extending
>> the
>> CamelSpringTestSupport class, not the AbstractJUnit4SupportTestCase.
>> I did not find any documentation about such a feature (injecting beans),
>> but
>> would it be something doable or is there a mistake/somthing missing in my
>> code ?
>> In the mean time, I can manually retrieve the bean from the
>> applicationContext, but using annotation would be nicer ;-)
>>
>> Thank you in advance
>> Regards,
>
>
> --
> Willem
> ----------------------------------
> FuseSource
> Web: http://www.fusesource.com
> Blog:    http://willemjiang.blogspot.com (English)
>         http://jnn.javaeye.com (Chinese)
> Twitter: willemjiang
>
> Connect at CamelOne May 24-26
> The Open Source Integration Conference
> http://camelone.com
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Mime
View raw message