spring的autowired与resource
经过工作中的开发经验可以用一句话进行总结其区别与联系:
@autowired与@resource就只是默认的装配类型不一致,@autowired默认byType注入,如果找不到byType(也就是一个接口的实现类有多个),那么就按照byName注入。@resource是默认按照byName注入,当byName找不到的时候,则按照byType注入。代码如下:
@autowired示例
@Component
public class IndexDaoImpl implements IndexDao {
原创
2020-10-13 18:49:35 ·
451 阅读 ·
0 评论