All About Spring
Spring IoC 控制反转
https://www.cnblogs.com/joy99/p/10842218.html
将创建对象的控制权交给了spring这个大容器(工厂),对象不再由我们来创建,而是由spring帮我们构建。
注解
-
@Component
标在实体类前面,让Scanner来扫描并注入 -
@Autowired
@Autowired
private UserRepository userRepository;
自动装配。从IoC容器中去查找到,并返回给该属性
-
@Configuration
-
@Bean
- Bean的作用域 @Scope("singleton")
singleton单例/prototype原型模式/request/session/global session - 延迟加载 @Lazy
- 初始化@PostConstruct 销毁前@PreDestroy
- Bean的作用域 @Scope("singleton")
构造注入与设值注入
构造注入:Person p = new Person("xx");
设值注入:p.setPerson("xx")
浙公网安备 33010602011771号