Spring
singleton:单例模式,只初始化一个实例
prototype:原型模式,每次通过getBean方法都将产生一个Bean实例
request:对于每次HTTP的请求,都产生一个新的实例
Session:地狱与每次HttpSesson都产生一个新的实例,
global session:每个全局的HTTP Session对应一个Bean实例,
比较常用的是singleton和prototype
自动装配类型:byname and bytype
在使用自动装配过程中要注意好bean的类型,否则很容易出现异常
注入嵌套bean
如果不行让spring外部访问bean可以采用嵌套bena的方法
设计模式单例模式
private static Singleton instance;
private Singleton(){
if(instance==null){
instance=new Singleton();
}
return instance;
}
简单工厂模式
private Output out;
publlic Compute(Out out){
this.out=out;
}