CTO 说了,用错 @Autowired 和 @Resource 的人可以领盒饭了
共 6222字,需浏览 13分钟
·
2021-06-13 02:38
阅读本文大概需要 4 分钟。
作者:liuxuzxx
来源:juejin.cn/post/6844904064212271117
介绍
@Autowire
private JdbcTemplate jdbcTemplate;
注入方式
public class UserServiceImpl implents UserService{
private UserDao userDao;
@Autowire
public UserServiceImpl(UserDao userDao){
this.userDao = userDao;
}
}
public class UserServiceImpl implents UserService{
private UserDao userDao;
@Autowire
public serUserDao(UserDao userDao){
this.userDao = userDao;
}
}
public class UserServiceImpl implents UserService{
@Autowire
private UserDao userDao;
}
基于字段的依赖注入缺点
public class VerifyServiceImpl implents VerifyService{
private AccountService accountService;
private UserService userService;
private IDService idService;
private RoleService roleService;
private PermissionService permissionService;
private EnterpriseService enterpriseService;
private EmployeeService employService;
private TaskService taskService;
private RedisService redisService;
private MQService mqService;
public SystemLogDto(AccountService accountService,
UserService userService,
IDService idService,
RoleService roleService,
PermissionService permissionService,
EnterpriseService enterpriseService,
EmployeeService employService,
TaskService taskService,
RedisService redisService,
MQService mqService) {
this.accountService = accountService;
this.userService = userService;
this.idService = idService;
this.roleService = roleService;
this.permissionService = permissionService;
this.enterpriseService = enterpriseService;
this.employService = employService;
this.taskService = taskService;
this.redisService = redisService;
this.mqService = mqService;
}
}
结论
后记
推荐阅读:
华为天才少年,造出自动驾驶单车!图纸已开源,重新定义「自行」车!
微信扫描二维码,关注我的公众号
朕已阅