inject a mockups to a bean that has @autowired annotations

Posted by santiagozky on Stack Overflow See other posts from Stack Overflow or by santiagozky
Published on 2010-05-07T15:01:59Z Indexed on 2010/05/07 15:08 UTC
Read the original article Hit count: 396

Filed under:
|

I have a bean that has a couple of beans injected with the autowire annotation (no qualifier). Now, for testing reasons I want to inject some mocks to the bean instead of the ones being autowired (some DAOs). Is there any way I can change which bean is being injected without modifying my bean? I don't like the idea of adding annotations my code just to test it and then remove then for production. I am using spring 2.5.

The bean look like this:

@Transactional  
@Service("validaBusinesService")  
public class ValidaBusinesServiceImpl implements ValidaBusinesService {

    @Autowired  
    OperationDAO operationDAO;  
    @Autowired  
    BinDAO binDAO;  
    @Autowired  
    CardDAO cardDAO;  
    @Autowired  
    UserDAO userDAO;  

    ...
    ...
}

© Stack Overflow or respective owner

Related posts about spring

Related posts about java