求高手解释Spring3.2参考手册上的一段话

问题描述

rt,最好举一些例子~~ 看了几遍理解不了~ 谢谢!spring 3.2 参考手册160页。内容如下:Glue code and the evil singletonIt is best to write most application code in a dependency-injection (DI) style, where that code is servedout of a Spring IoC container, has its own dependencies supplied by the container when it is created, andis completely unaware of the container. However, for the small glue layers of code that are sometimesneeded to tie other code together, you sometimes need a singleton (or quasi-singleton) style accessto a Spring IoC container. For example, third-party code may try to construct new objects directly(Class.forName() style), without the ability to get these objects out of a Spring IoC container. If theobject constructed by the third-party code is a small stub or proxy, which then uses a singleton styleaccess to a Spring IoC container to get a real object to delegate to, then inversion of control has still beenachieved for the majority of the code (the object coming out of the container). Thus most code is stillunaware of the container or how it is accessed, and remains decoupled from other code, with all ensuingbenefits. EJBs may also use this stub/proxy approach to delegate to a plain Java implementation object,retrieved from a Spring IoC container. While the Spring IoC container itself ideally does not have to bea singleton, it may be unrealistic in terms of memory usage or initialization times (when using beans inthe Spring IoC container such as a Hibernate SessionFactory) for each bean to use its own, non-singleton Spring IoC container. 问题补充:Glue code and the evil singletonIt is best to write most application code in a dependency-injection (DI) style, where that code is servedout of a Spring IoC container, has its own dependencies supplied by the container when it is created, andis completely unaware of the container. However, for the small glue layers of code that are sometimesneeded to tie other code together, you sometimes need a singleton (or quasi-singleton) style accessto a Spring IoC container. For example, third-party code may try to construct new objects directly(Class.forName() style), without the ability to get these objects out of a Spring IoC container. If theobject constructed by the third-party code is a small stub or proxy, which then uses a singleton styleaccess to a Spring IoC container to get a real object to delegate to, then inversion of control has still beenachieved for the majority of the code (the object coming out of the container). Thus most code is stillunaware of the container or how it is accessed, and remains decoupled from other code, with all ensuingbenefits. EJBs may also use this stub/proxy approach to delegate to a plain Java implementation object,retrieved from a Spring IoC container. While the Spring IoC container itself ideally does not have to bea singleton, it may be unrealistic in terms of memory usage or initialization times (when using beans inthe Spring IoC container such as a Hibernate SessionFactory) for each bean to use its own, non-singleton Spring IoC container.

解决方案

粘合代码和讨厌的单例(消除了编程实现单例)最好是大多数应用程序代码使用依赖项注入(DI)风格进行编写,一个IoC容器服务于该代码,由容器提供它自己的依赖,当它被创建时,它是完成不知道容器的。然而,对于小规模的粘合层代码,有时候需要关联其他代码,你有时候需要一个单例(或 类似单例)风格访问Spring IoC容器。例如,第三方代码可能设法直接构建新的对象(Class.forName() 风格),无法从一个Spring IoC容器中获取这些对象。如果第三方代码构建的对象是一个小的stub 或 proxy,然后使用单例风格访问Spring IoC容器来获取一个真实的对象并委托给它,那么控制反仍然实现了大部分代码(容器生产对象)。因此,大多数代码仍然是不知道容器的或它是如何被访问的,且仍然是和其他代码解耦的,拥有所有因此产生的好处。EJB也可以使用这种stub/proxy方法委托给一个从Spring IoC容器中取出的普通Java实现对象。虽然Spring IoC容器本身理想情况下不必是一个单例,非单例Spring IoC容器可能在内存使用期间是不切实际的或在初始化时间每一个Bean使用它(当使用的Bean在Spring IoC容器中,如Hibernate SessionFactory)。

时间: 2024-09-20 19:29:53

求高手解释Spring3.2参考手册上的一段话的相关文章

oralce 语句问题 求高手解释。

问题描述 oralce 语句问题 求高手解释. select to_number(to_char(add_months(a1.time_sh month - 1) 'yyyymm')) end_time--结束月份 to_number(to_char(a1.time_sh 'yyyymm')) start_timea1.time_sh from c_wzxx a1 解决方案 这自己搜一下add_months ,to_char,to_number 这几个函数的意思就行了

一小段Java代码求高手解释,严重求助!!!!!

问题描述 小弟我对Java一窍不通,惭愧,只学过VB,正在强化自己,下面的代码只看懂了一点,这段代码在VB.net中如何实现的?,求高手转换成VB代码好么!小弟不才,看懂的加了VB注释.数字转MD5后=7C6DF7FC35DDCF4AD9BE46F4FFDD58DE,从第13位开始取值12位等于CF4AD9BE46F4,最后的计算结果是661-273-276-329好像还有一个翻转函数publicstaticStringreverse(char[]paramArrayOfChar)小弟先谢谢大侠

求高手帮助!手机端网页上传照片有没有js+.net语言,项目用的MVC

问题描述 遇到其他的手机端上传图片个别用的是php,这点不会!想找个.net版的!求帮助 解决方案 解决方案二:上传图片前端都一样,都是依赖js,后端就是接收数据而已,这个各个语言怎么实现随便找下就可以了解决方案三:bootstrap

求高手解释API中这2句话。。很难理解

问题描述 java.awt接口TransparencyGraphicsConfigurationgc;BuffedImagebuf=gc.createCompatibleImage(intwidth,intheight,inttransparency);如果transparency=Transparency.BITMASK所创建的buf中的alpha到底是1.0还是0.0!!staticfinalintBITMASK表示保证完全不透明的图像数据(alpha值为1.0)或完全透明的图像数据(alp

求高手帮我看看这个hibernate的问题啊!

问题描述 在record里面没有设置id的值,因为在数据库里面的自增的!public long insertUser(WebUser record) { Session session=null; long id=0; try{ session=sessionFactory.getCurrentSession(); session.beginTransaction(); session.save(record); id=record.getId(); session.getTransaction

算法-求高手,java如何做到几十毫秒ac的

问题描述 求高手,java如何做到几十毫秒ac的 为什么我交的代码都要200以上,就连简单的a+b都是,求高手解释 解决方案 import java.util.Scanner;public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ System.out.println(sc.nextInt()+sc.nextInt()

MySQL中文参考手册5(安装MySQL上)

mysql|参考|参考手册|中文 MySQL中文参考手册5(安装MySQL上)转载 译者:晏子 [返回][转发] 译者:晏子 (clyan@sohu.com)主页:http://linuxdb.yeah.net4 安装MySQL本章描述怎样获得并安装MySQL:  对于你能从其获得MySQL的站点列表,见4.1 怎样获得MySQL. 要了解支持哪些平台,见4.2 MySQL支持的操作系统. 可获得MySQL的多个版本,以二进制代码和源代码形式分发.为了确定你应该使用的分发的版本和类型,见4.4 

c语言-C语言===参考答案为A,求详细解释

问题描述 C语言===参考答案为A,求详细解释 已知int i=0,j=1,*p=&i,*q=&j;错误的语句是: A)i=*&q; B)p=&*&i; C)j=*p++; D)i=*&j; ===参考答案为A,求详细解释 解决方案 q是j的地址 i等于赋予了j的地址 解决方案二: &是取地址*是寻址(解引用)所以 q 指针 所指内存中存的是j的地址 也就是*q=0x0003(j的地址) 指针*q又有自己的地址q==0x0001 理解了上述就可以明白

List里存储的数据库数据怎么到页面上显示都是0呢?求高手解答

问题描述 我的UserAction里的代码如下:privateList<UserBean>findAllUser(){log.info("getalluserinf...");List<UserBean>list=newArrayList<UserBean>();UserBeanuser;Connectionconn=getConn();Stringsql="SELECT*FROMusersORDERBYno";PreparedS