我们的项目是mvc架构,在action层有这样的一段代码:
@Autowired
private AccountService accountService;
我觉得这样的话,是把AccountService注入到了AccountAction,怎么会是把AccountService的实现AccountServiceImpl注入给了AccountAction呢?
因为@Autowired这个注解就是根据类型来匹配的啊,匹配的也就是应该AccountService啊?
[b]问题补充:[/b]
晕,既然是注解了,在xml里就没有(或者不需要)配AccountServiceImpl了啊
[b]问题补充:[/b]
对,这些我都清楚,我的意思是spring容器怎么就会去找AccountServiceImpl,而不是去找其他呢?根据是什么呢?
或者说我再给它一个注解:Qualifier("accountServiceImpl"),spring容器怎么就会把AccountServiceImpl自动注入给AccountAction了,就是说这个名称(accountServiceImpl)是怎么跟AccountServiceImpl关联起来的?而不去关联其他的:比如AccountServiceImpl1、AccountServiceImpl2等等。