0
点赞
收藏
分享

微信扫一扫

spring的三种注入的区别


@Resource

按名称注入

@Autowired

按类型注入

@RequiredArgsConstructor和private final TestService testService

按类型注入,不允许服务之间循环依赖
如:
TestServiceImpl
TestServiceImpl2
若:
TestServiceImpl里面写了: private final TestService2 testService2那么,在TestServiceImpl2就不能再写: private final TestService testService

解决方法:

@RequiredArgsConstructor(onConstructor = @__(@Autowired))
或改用@Resource或@Autowired


举报

相关推荐

0 条评论