在Spring容器中为一个bean配置依赖注入有三种方式:

  • 使用属性的setter方法注入
  • 使用构造器注入;
  • 注解方式

1. 使用属性的setter方法注入

也就是基于xml的开发
spring依赖注入(IOC)
spring依赖注入(IOC)

2. 使用字段(Filed)注入(用注解方式)

spring依赖注入(IOC)

spring依赖注入(IOC)

spring依赖注入(IOC)

3. 构造器注入:

通过将@Autowired注解放在构造器上来完成构造器注入,默认构造器参数通过类型自动装配,

spring依赖注入(IOC)

相关文章:

  • 2020-05-27
  • 2021-02-25
  • 2021-08-20
  • 2021-02-28
  • 2020-03-26
  • 2020-06-11
  • 2019-09-24
  • 2021-06-29
猜你喜欢
  • 2021-01-27
  • 2018-02-03
  • 2020-03-17
  • 2021-02-27
  • 2020-04-15
  • 2019-06-26
  • 2020-07-14
  • 2020-05-12
相关资源
相似解决方案