1.Spring的作用域
当spring创建对象时,会默认为每个bean声明一个作用域 非web环境 :singletone propertype web环境:request session globle session application 具体每个作用域的使用方法参见 这篇博客:https://blog.csdn.net/chen213wb/article/details/81278683
2.spring创建bean的方式
一共有3中方法
如果采用xml的方法:
a。使用构造器的方法 包括无参构造 有参构造
b。静态工厂方法
c。实例工厂
bean多了以后 会导致xml膨胀,推荐使用
使用@Component,@Service,@Controler,@Repository注解
spring的ioc的实现 是依靠依赖注入 来实现的 依赖注入有3中方式 1.构造注入 2.set注入 3.注解注入。其中注解注入,需要将将依赖的对象提前注入到Spring的容器中。
3.Spring bean的生命周期
1.实例化(调用bean构造方法进行构造方法) 2.初始化(执行init方法) 3. bean开始使用 4.bean销毁
4.springmvc中的controller如何保证成员变量线程安全?
1.使用scope 注解 变成session
2.使用threadloacl来修饰 该变量。