依赖注入
一,构造器注入
上一篇已经写过,不做赘述
二,set方式注入(重点)
依赖注入:Set注入!
依赖:bean对象的创建依赖容器
注入:bean对象所有的属性,由容器注入
环境搭建
1.复杂类型
2.真实测试对象
3.beans.xml
<?xml version="1.0" encoding="UTF-8"?>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
红楼梦
西游记
水浒传
三国演义
听歌
敲代码
看电影
LOL
BOB
COC
1812230104
男
root
123456
4.测试
三,拓展方式注入
p命名空间注入和c命名空间注入
p命名空间和c命名空间不能直接使用,需要导入xml约束
四,bean的作用域
singleton
prototype
request
session
application
websocket
1.单例模式(spring默认机制)
singleton
2.原型模式:每次从容其中get的时候,会生成一个新的对象
prototype
测试
reques,session,application这些在web开发中使用到