unit testing - How to override the behavior of Spring @Autowired -


A small background:

I'm using Spring 2.5, and especially the Spring IOC and annotations .

I am using @ etowold in my code (done by automating type) and to highlight classes for automatic coding, @Component Use .

For the problem now:

Note: I use a different spring reference for the testing environment.

/ P>

I have a class FOO which is @Autowired but in the context of testing, I use a different class of the same type I want to MockFoo (expansion FOO ). The spring setup of the course fails automatically (both FOO and MockFoo

/ Code> follow the type check).

I am exploring a method to inject the test bean instead of the original bean.

I exp has to use a config configuration file to override a bean injection to spring or to allow the spring to order spring.

But

But all these options are present only for beans which was originally defined in the spring reference configuration file.

Manually duplicate set Autowired dependencies (for that purpose you should not manage your fake spring, So that no ambiguity exists)


Comments