(面试)对spring的理解?
来源:互联网 发布:boljoo蒙语软件下载 编辑:程序博客网 时间:2024/05/16 15:20
1.Spring实现了工厂模式的工厂类(在这里有必要解释清楚什么是工厂模式),这个类名为BeanFactory(实际上是一个接口),在程序中通常BeanFactory的子类ApplicationContext。Spring相当于一个大的工厂类,在其配置文件中通过<bean>元素配置用于创建实例对象的类名和实例对象的属性。
2. Spring提供了对IOC良好支持,IOC是一种编程思想,是一种架构艺术,利用这种思想可以很好地实现模块之间的解耦。IOC也称为DI(Depency Injection),什么叫依赖注入呢?
譬如,Class Programmer
{
Computer computer = null;
public void code()
{
//Computer computer = new IBMComputer();
//Computer computer = beanfacotry.getComputer();
computer.write();
}
public void setComputer(Computer computer)
{
this.computer = computer;
}
}
另外两种方式都由依赖,第一个直接依赖于目标类,第二个把依赖转移到工厂上,第三个彻底与目标和工厂解耦了。在spring的配置文件中配置片段如下:
<bean id=”computer” class=”cn.itcast.interview.Computer”>
</bean>
<bean id=”programmer” class=”cn.itcast.interview.Programmer”>
<property name=”computer” ref=”computer”></property>
</bean>
3. Spring提供了对AOP技术的良好封装, AOP称为面向切面编程,就是系统中有很多各不相干的类的方法,在这些众多方法中要加入某种系统功能的代码,例如,加入日志,加入权限判断,加入异常处理,这种应用称为AOP。实现AOP功能采用的是代理技术,客户端程序不再调用目标,而调用代理类,代理类与目标类对外具有相同的方法声明,有两种方式可以实现相同的方法声明,一是实现相同的接口,二是作为目标的子类在,JDK中采用Proxy类产生动态代理的方式为某个接口生成实现类,如果要为某个类生成子类,则可以用CGLI B。在生成的代理类的方法中加入系统功能和调用目标类的相应方法,系统功能的代理以Advice对象进行提供,显然要创建出代理对象,至少需要目标类和Advice类。spring提供了这种支持,只需要在spring配置文件中配置这两个元素即可实现代理和aop功能,例如,
<bean id=”proxy” type=”org.spring.framework.aop.ProxyBeanFactory”>
<property name=”target” ref=””></property>
<property name=”advisor” ref=””></property>
</bean>
- (面试)对spring的理解?
- 对SPRING的理解
- 对Spring 的理解
- 对Spring的理解
- 对Spring的理解
- 对spring的理解
- 对Spring的理解
- 对Spring的理解
- 对spring的理解
- 对spring的理解
- 对Spring的理解
- 对Spring IOC的理解(1)
- Spring初学三(对spring作为容器的理解)
- 对Spring Framework的理解
- 转帖 - 对Spring的理解
- 对spring AOP 的理解
- 对spring框架的理解
- 对spring的aop理解
- Qt中的串口编程之二
- 《Java 编程思想》--第十九章:枚举类型
- 启动Eclipse报错Failed to create the Java Virtual Machine
- 《Java 编程思想》--第二十章:注解
- msvcrt.lib和LIBCD.lib链接冲突
- (面试)对spring的理解?
- iftop实时流量监控
- 为Ubuntu安装翻译词典(星际译王)
- java警惕自增的陷阱
- oracle 11g 的启动命令
- RadHat linux下修改站点的默认路径
- Chemical Secret——10、Green world
- C++之智能指针
- (面试)Serverlet详解---生命周期