SpringBoot(??????)@Autowired???@Inject???@Resource

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot(??????)@Autowired???@Inject???@Resource相关的知识,希望对你有一定的参考价值。

?????????tor   ??????   tom   lock   javadoc   log   actor   post   auto   

@Resource,@Autowired,@Inject ???3?????????????????????bean????????????????????????????????????????????????????????????

v??????

ANNOTATIONPACKAGESOURCE???????????????????????????
@AutoWired org.springframework.bean.factory???Spring??????????????? Spring 2.5+ ??????????????????????????????????????????????????????????????? ??????AutowireAnnotationBeanPostProcessor????????????????????? ????????????????????????/?????????????????????required?????????false?????????????????????bean???????????????
@Resource javax.annotation,???JSR-250?????????JDK6????????????,Spring????????????2.5?????? Java JSR-250 ???????????????????????????????????? ??????CommonAnnotationBeanPostProcessor????????????????????? ???@AutoWired????????????????????????name???????????????beanName,?????????name?????????bean??????????????????????????????????????????required??????
@Inject javax.inject,???JSR-303?????????Spring??????3????????????????????????????????? Java JSR-330 ?????????????????????????????????????????? ??????AutowiredAnnotationBeanPostProcessor????????????????????? ???@AutoWired?????????????????????@Inject??????required??????

v????????????

2.1 @Inject

?????????@Inject??????????????????@Named????????????????????????????????????????????????

    @Inject
    @Named("mongo")
    private Mongo mongo;

2.2 @Autowired

@Autowired???????????????required??????????????????false??????????????????false??????????????????????????????bean?????????????????????????????????

    @Autowired
    private MongoTemplate mongoTemplate;

2.3 @Resource

@Resource?????????????????????name???????????????

    @Resource(name = "testMapper")
    private TestMapper testMapper;

以上是关于SpringBoot(??????)@Autowired???@Inject???@Resource的主要内容,如果未能解决你的问题,请参考以下文章

用于 Spring Boot 应用程序的 JUnit @BeforeClass 非静态工作

MybatisPlus使用介绍

JedisPool实现

SpringIOC的循环依赖解析

模拟私有方法[重复]

3.Sprint 代理对象与原始对象的异常错误