1、Spring和Struts的区别?
strusts:是一种基于MVC模式的一个web层的处理。
Spring:提供了通用的服务,ioc/di aop,关心的不仅仅web层,应当j2ee整体的一个服务,可以很容易融合不同的技术struts hibernate ibatis ejb remote springJDBC springMVC
2、什么是aop,aop的作用是什么?
Oop:纵向的业务
Aop:oop的一个横向的服务,是对oop进一步的补充,提供安全、事务、日志等的集中式处理,相关的装备before、around、after exception
3、aop中的关键名词有些那些,相互关系是什么?
拦截器: 代理
装备(advice)
目标对象
关切点:条件
连接点:方法、属性
4、依赖注入的方式有几种,各是什么?
Setter
Interface
constructor
5、spring中的核心类有那些,各有什么作用?
BeanFactory:产生一个新的实例,可以实现单例模式
BeanWrapper:提供统一的get及set方法
ApplicationContext:提供框架的实现,包括BeanFactory的所有功能
6、ApplicationContext的作用
beanFactory
国际化(getMesage)
资源管理:可以直接读取一个文件的内容(getResource)
加入web框架中(加入一个servlet或监听器)
事件处理
7、如何实现资源管理
使用
applicationContext.getResource(“classpath:文件名”):在src根目录下,在类路径下
applicationContext.getResource(“classpath:/chap01/文件名”): 以src根目录下的基准往下走。
applicationContext.getResource(“file:c:/a.properties”):在系统文件目录下。
8、如何实现加入web框架中
在web.xml中加入如下同容,在启动web服务器时加载/WEB-INF/applicationContext.xml中的内容。
context
org.springframework.web.context.ContextLoaderServlet
1
通过如下类得到ApplicationContext实例
WebApplicationContextUtils.getWebApplicationContext
9、如何实现事件处理
事件
Extends ApplicationEvent
监听器
Implements ApplicationListener
事件源
Implements ApplicationContextAware
在applicationContext.xml中配置事件源、监听器
先得到事件源,调用事件源的方法,通知监听器。
10、spring的ioc及di代表什么意思?
Ioc:程序在运行过程中,根据配置文件动态加载所依赖的配置类
11、如何在spring中实现国际化?
在applicationContext.xml加载一个bean
message
Ø 在src目录下建多个properties文件
Ø 对于非英文的要用native2ascii -encoding gb2312 源 目转化文件相关内容
其命名格式是message_语言_国家。
Ø 页面中的中显示提示信息,键名取键值。
Ø 当给定国家,系统会自动加载对应的国家的properties信息。
Ø 通过applictionContext.getMessage(“键名”,”参数”,”区域”)取出相关的信息。
12、spring与ejb2.0的事务管理比较的优缺点?
测试:
Spring:pojo
Ejb:二个接口一个类,一堆配置文件
事务类型
Spring:jdbc jta hibernate
Ejb:jta
成本
Spring:普通容器(tomcat jboss)
Ejb:weblogic jboss
开发的周期:
Spring远比ejb快.
13、spring的jdbc与传统的jdbc有什么区别,其核心类有哪些?
Spring的jdbc:节省代码,不管连接(Connection),不管事务、不管异常、不管关闭(con.close() ps.close )
JdbcTemplate(dataSource):增、删、改、查
TransactionTemplate(transactionManager):进行事务处理
14、在spring中有几种事务管理,分别是什么?
代码管理的事务处理
TransactonTemplate的execute方法中的内部类TransactionCallback中的doInTransaction方法中使用。
public void make()
{
TransactionTemplate jtm=new TransactionTemplate(this.getTransactionManager());
jtm.execute(new myClass1());
}
public class myClass1 implements TransactionCallback
{
public Object doInTransaction(TransactionStatus trans)
{
JdbcTemplate jdbc=new JdbcTemplate(dataSource);
jdbc.execute(“insert into customer(customerName) values(‘b’)”);
jdbc.execute(“insert into customer(customerName) values(‘b’)”);
return null;
}
}
容器管理的事务处理
15、在spring中如何配代码的事务管理?
Datasouce
transactionManager
userDao要注入
Datasouce
transactionManager
通过如下类实现
TransactionTemplate
JdbcTemplate
16、在spring中如何配容器的事务管理,相关的类有哪些?
Datasouce
transactionManager
userDao要注入
Datasouce
Proxy代理
Target:userDao:代理对象(目标对象)
transactionAttributes(那些方法需要事务处理)
transactionManager(事务处理服务)
17、如果spring与hibernate结合在一起可以不需要hibernate.cfg.xml文件是否正确?
不需要
18、spring+hibernate的配置文件中的主要类有那些?如何配置?
在myeclipse中先加入spring环境再加入hibernate环境。
如果spring与hibernate结合在一起可以不需要hibernate.cfg.xml文件是否正确?
spring+hibernate的配置文件中的主要类有那些?如何配置?
dataSource
sessionFactory:hibernate.cfg.xml
transactionManager
userDao (extends HibernateDaoSupport)
sessionFactory
facade
proxy
sessionFactory
transactionManager
facade
19、spring+hibernate的代码实现中,对于实现类一定继承于一个类是那一个,它有什么作用。
extends HibernateDaoSupport,可以节省代码。
20、如何配置spring+struts?
在struts-config.xml加入一个插件,通过它加载applicationContext.xml
Ø 在struts-config.xml修改action-mapping标记,具体action交给了DelegateActionProxy
u 通过DelegateActionProxy进入一spring的环境。
Ø 在spring的applicationContext.xml加入
21、如何在web环境中配置applicationContext.xml文件?
org.springframework.web.context.ContextLoaderListener
或:
context
org.springframework.web.context.ContextLoaderServlet
1
通过如下方法取出applicationContext实例:
ApplicationContext ac=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext);
22、Jsf和spring的区别?
jsf:是一种基于MVC模式的一个web层的处理,粒度较struts较细。
Spring:提供了通用的服务,ioc/di aop,关心的不仅仅web层,应当j2ee整体的一个服务,可以很容易融合不同的技术struts hibernate ibatis ejb remote springJDBC springMVC
想获取更多资讯、更多视频、面试题答案,还有各种资源+源码+工具 就关注“蛙课网校”公众号吧!
