spring常会面试题

spring常见面试题

http://www.mianwww.com/html/category/it-interview/spring/


Spring框架的优点都有什么?

<!-- [entry] -->
Spring是分层的架构,你可以选择使用你需要的层而不用管不需要的部分 Spring是POJO编程,POJO编程使得可持续构建和可测试能力提高依赖注入和IoC使得JDBC操作简单化 Spring是开源的免费的 Spring使得对象管理...... <阅读全文>
<!-- [post] -->

描述一下Spring中实现DI(Dependency Injection)的几种方式

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
方式一:接口注入,在实际中得到了普遍应用,即使在IOC的概念尚未确立时,这样的方法也已经频繁出现在我们的代码中。方式二:Type2 IoC: Setter injection对象创建之后,将被依赖对象通过set方法设置进去方...... <阅读全文>
<!-- [post] -->

简述你对IoC(Inversion of Control)的理解

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
一个类需要用到某个接口的方法,我们需要将类A和接口B的实现关联起来,最简单的方法是类A中创建一个对于接口B的实现C的实例,但这种方法显然两者的依赖(Dependency)太大了。而IoC的方法是只在类A中定义好用...... <阅读全文>
<!-- [post] -->

Spring对多种ORM框架提供了很好的支持,简单描述在Spring中使用Hibernate的方法。

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
在context中定义DataSource,创建SessionFactoy,设置参数;DAO类继承HibernateDaoSupport,实现具体接口,从中获得HibernateTemplate进行具体操作。在使用中如果遇到OpenSessionInView的问题,可以添加OpenSe...... <阅读全文>
<!-- [post] -->

请介绍一下Spring的事务管理

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
spring提供了几个关于事务处理的类: TransactionDefinition //事务属性定义 TranscationStatus //代表了当前的事务,可以提交,回滚。 PlatformTransactionManager这个是spring提供的用于管理事务的基础接口...... <阅读全文>
<!-- [post] -->

如何在Spring的applicationContext.xml里面使用JNDI而不是datasource?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
可以使用”org.springframework.jndi.JndiObjectFactoryBean”来实现。示例如下: <bean id=”dataSource”>     <property name=”jndiName”>         <value...... <阅读全文>
<!-- [post] -->

Spring里面如何配置数据库驱动?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
使用”org.springframework.jdbc.datasource.DriverManagerDataSource”数据源来配置数据库驱动。示例如下: <bean id=”dataSource”>     <property name=”driverClassN...... <阅读全文>
<!-- [post] -->

Spring里面applicationContext.xml文件能不能改成其他文件名?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
ContextLoaderListener是一个ServletContextListener, 它在你的web应用启动的时候初始化。缺省情况下, 它会在WEB-INF/applicationContext.xml文件找Spring的配置。 你可以通过定义一个<context-param>...... <阅读全文>
<!-- [post] -->

如何在web应用里面配置spring?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
在J2EE的web应用里面配置spring非常简单,最简单的只需要把spring得ContextLoaderListener添加到你的web.xml文件里面就可以了,示例如下: <listener>     <listener-class>org.springframework.w...... <阅读全文>
<!-- [post] -->

Spring里面如何定义hibernate mapping?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
添加hibernate mapping 文件到web/WEB-INF目录下的applicationContext.xml文件里面。示例如下: <property name=”mappingResources”>     <list>         <value>org/appfuse/m...... <阅读全文>
<!-- [post] -->

两种依赖注入的类型都是什么?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
两种依赖注入的类型分别是setter注入和构造方法注入。 setter注入: 一般情况下所有的java bean, 我们都会使用setter方法和getter方法去设置和获取属性的值,示例如下: public class namebean {      String ...... <阅读全文>
<!-- [post] -->

解释一下Dependency injection(DI,依赖注入)和IOC(Inversion of control,控制反转)?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
参考答案:依赖注入DI是一个程序设计模式和架构模型, 一些时候也称作控制反转,尽管在技术上来讲,依赖注入是一个IOC的特殊实现,依赖注入是指一个对象应用另外一个对象来提供一个特殊的能力,例如:把一个数...... <阅读全文>
<!-- [post] -->

spring中的BeanFactory与ApplicationContext的作用和区别?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
作用: 1. BeanFactory负责读取bean配置文档,管理bean的加载,实例化,维护bean之间的依赖关系,负责bean的声明周期。 2. ApplicationContext除了提供上述BeanFactory所能提供的功能之外,还提供了更完整的框...... <阅读全文>
<!-- [post] -->

如何在web环境中配置applicationContext.xml文件?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
<listener>   <listener-class>    org.springframework.web.context.ContextLoaderListener   </listener-class>  </listener>  或:  <servlet>   <servlet-name>conte...... <阅读全文>
<!-- [post] -->

如何配置spring+struts?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a>, <a href="http://www.mianwww.com/html/category/it-interview/struts-it-interview" title="View all posts in Struts" rel="category tag">Struts</a></span>-->
<!-- [entry] -->
在struts-config.xml加入一个插件,通过它加载applicationContext.xml  在struts-config.xml修改action-mapping标记,具体action交给了DelegateActionProxy  通过DelegateActionProxy进入一spring的环境。...... <阅读全文>
<!-- [post] -->

spring+hibernate的配置文件中的主要类有那些?如何配置?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
在myeclipse中先加入spring环境再加入hibernate环境。  如果spring与hibernate结合在一起可以不需要hibernate.cfg.xml文件是否正确?  spring+hibernate的配置文件中的主要类有那些?如何配置?   dataSource   s...... <阅读全文>
<!-- [post] -->

在spring中如何配容器的事务管理,相关的类有那些?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
Datasouce    transactionManager    userDao要注入     Datasouce    Proxy代理     Target:userDao:代理对象(目标对象)     transactionAttributes(那些方法需要事务处理)     transactionManager(事务处理...... <阅读全文>
<!-- [post] -->

在spring中如何配代码的事务管理?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
Datasouce    transactionManager    userDao要注入     Datasouce     transactionManager   通过如下类实现     TransactionTemplate     JdbcTemplate Click me to Bookmark It! Hide ...... <阅读全文>
<!-- [post] -->

在spring中有几种事务管理,分别是什么?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
代码管理的事务处理 TransactonTemplate的execute方法中的内部类TransactionCallback中的doInTransaction方法中使用。 public void make()  {    TransactionTemplate jtm=new TransactionTemplate(this.getTr...... <阅读全文>
<!-- [post] -->

spring的jdbc与传统的jdbc有什么区别,其核心类有那些?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
Spring的jdbc:节省代码,不管连接(Connection),不管事务、不管异常、不管关闭(con.close() ps.close )   JdbcTemplate(dataSource):增、删、改、查   TransactionTemplate(transactionManager):进行事务处理 ...... <阅读全文>
<!-- [post] -->

spring与ejb2.0的事务管理比较的优缺点?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
测试:    Spring:pojo    Ejb:二个接口一个类,一堆配置文件事务类型    Spring:jdbc jta  hibernate    Ejb:jta 成本      Spring:普通容器(tomcat jboss)      Ejb:weblogic jboss 开发的周期:    Spring远...... <阅读全文>
<!-- [post] -->

spring的配置的主要标签是什么?有什么作用?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
<beans>    <bean id=”” class=”” init=”” destroy=”” singleton=””>     <property name=””>      <value></value>     </property>     <property name=””>     ...... <阅读全文>
<!-- [post] -->

如何在spring中实现国际化?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
 在applicationContext.xml加载一个bean <bean id=”messageSource” class=”org.springframework.context.support.ResourceBundleMessageSource”>   <property name=”b...... <阅读全文>
<!-- [post] -->

Spring如何实现事件处理?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
事件   Extends ApplicationEvent 监听器   Implements ApplicationListener 事件源   Implements ApplicationContextAware 在applicationContext.xml中配置事件源、监听器先得到事件源,调用事件源的方法,...... <阅读全文>
<!-- [post] -->

如何加入Spring到web框架中?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
在web.xml中加入如下同容,在启动web服务器时加载/WEB-INF/applicationContext.xml中的内容。 <servlet> <servlet-name>context</servlet-name> <servlet-class> org.springframework....... <阅读全文>

Spring如何实现资源管理?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
使用 applicationContext.getResource(“classpath:文件名”):在src根目录下,在类路径下 applicationContext.getResource(“classpath:/chap01/文件名”): 以src根目录下的基准往下走。 applicationContext.getRe...... <阅读全文>
<!-- [post] -->

Spring中ApplicationContext的作用是什么?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
beanFactory 国际化(getMesage) 资源管理:可以直接读取一个文件的内容(getResource) 加入web框架中(加入一个servlet或监听器) 事件处理 Click me to Bookmark It! Hide Sites $$('div....... <阅读全文>
<!-- [post] -->

spring中的核心类有那些,各有什么作用?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
BeanFactory:产生一个新的实例,可以实现单例模式 BeanWrapper:提供统一的get及set方法 ApplicationContext:提供框架的实现,包括BeanFactory的所有功能 Click me to Bookmark It! Hide...... <阅读全文>
<!-- [post] -->

aop中的关键名词有些那些,相互关系是什么?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
拦截器: 代理装备(advice) 目标对象关切点:条件连接点:方法、属性 Click me to Bookmark It! Hide Sites $$('div.d3155').each( function(e) { e.visualEffect('slide_up',{duratio...... <阅读全文>
<!-- [post] -->

Spring和Struts的区别?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a>, <a href="http://www.mianwww.com/html/category/it-interview/struts-it-interview" title="View all posts in Struts" rel="category tag">Struts</a></span>-->
<!-- [entry] -->
strusts:是一种基于MVC模式的一个web层的处理。 Spring:提供了通用的服务,ioc/di aop,关心的不仅仅web层,应当j2ee整体的一个服务,可以很容易融合不同的技术struts hibernate ibatis ejb remote springJDBC...... <阅读全文>
<!-- [post] -->

struts+spring面试题

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a>, <a href="http://www.mianwww.com/html/category/it-interview/struts-it-interview" title="View all posts in Struts" rel="category tag">Struts</a></span>-->
<!-- [entry] -->
1.struts Action是不是线程安全的?如果不是,有什么方式可以保证Action的线程安全?如果是,说明原因 2.MVC,分析一下struts是如何实现MVC的 3.struts中的几个关键对象的作用(说说几个关键对象的作用) 4.spri...... <阅读全文>
<!-- [post] -->

Struts,Spring,Hibernate面试题总结

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/hibernate" title="View all posts in Hibernate" rel="category tag">Hibernate</a>, <a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a>, <a href="http://www.mianwww.com/html/category/it-interview/struts-it-interview" title="View all posts in Struts" rel="category tag">Struts</a></span>-->
<!-- [entry] -->
转载地址:http://blog.****.net/David8631/archive/2008/07/19/2676615.aspx Hibernate工作原理及为什么要用?原理: 1. 读取并解析配置文件 2. 读取并解析映射信息,创建SessionFactory 3. 打开Sesssion 4....... <阅读全文>
<!-- [post] -->

一些Spring和Hibernate的面试题(附答案)

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/hibernate" title="View all posts in Hibernate" rel="category tag">Hibernate</a>, <a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
1、 简述你对IoC(Inversion of Control)的理解,描述一下Spring中实现DI(Dependency Injection)的几种方式。 2、 Spring的Bean有多种作用域,包括: singleton、prototype、request、session、global sess...... <阅读全文>
<!-- [post] -->

请你谈谈SSH整合

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/hibernate" title="View all posts in Hibernate" rel="category tag">Hibernate</a>, <a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a>, <a href="http://www.mianwww.com/html/category/it-interview/struts-it-interview" title="View all posts in Struts" rel="category tag">Struts</a></span>-->
<!-- [entry] -->
SSH: Struts(表示层)+Spring(业务层)+Hibernate(持久层) Struts: Struts是一个表示层框架,主要作用是界面展示,接收请求,分发请求。在MVC框架中,Struts属于VC层次,负责界面表现,负责MVC关系的分...... <阅读全文>
<!-- [post] -->

在Spring框架中如何更加高效的使用JDBC

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
使用Spring框架提供的模板类JdbcTemplete可以是JDBC更加高效代码如下:JdbcTemplate template = new JdbcTemplate(myDataSource); DAO类的例子: public class StudentDaoJdbc implements StudentDao { priva...... <阅读全文>
<!-- [post] -->

Spring如何创建一个数据连接池

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
<bean id=”dataSource” class=”org.apache.commons.dbcp.BasicDataSource”> <property name=”driver”> <value>${db.driver}</value> </prop...... <阅读全文>
<!-- [post] -->

Spring如何配置一个bean来从JNDI得到DataSource

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
<bean id=”dataSource” class=”org.springframework.jndi.JndiObjectFactoryBean”> <property name=”jndiName”> <value>java:comp/env/jdbc/...... <阅读全文>
<!-- [post] -->

请介绍一下Spring框架中Bean的作用域

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
在spring2.0之前bean只有2种作用域即:singleton(单例)、non-singleton(也称 prototype),Spring2.0以后,增加了session、request、global session三种专用于Web应用程序上下文的Bean。因此,默认情况下Spri...... <阅读全文>
<!-- [post] -->

请介绍一下Spring框架中Bean的生命周期

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
一、Bean的定义 Spring通常通过配置文件定义Bean。如: <?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.springframework.org/schema/beans”...... <阅读全文>
<!-- [post] -->

Spring如何获取Bean

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
通过xml配置文件 bean配置在xml里面,spring提供多种方式读取配置文件得到ApplicationContext. 第一种方式:FileSystemXmlApplicationContext 通过程序在初始化的时候,导入Bean配置文件,然后得到Bean实例: A...... <阅读全文>
<!-- [post] -->

Spring框架有哪几部分组成?

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
Spring框架有七个模块组成组成,这7个模块(或组件)均可以单独存在,也可以与其它一个或多个模块联合使用,主要功能表现如下: ☞ Spring 核心容器(Core):提供Spring框架的基本功能。核心容器的主要组件是Bea...... <阅读全文>
<!-- [post] -->

使用Spring有什么好处

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
◆Spring能有效地组织你的中间层对象,无论你是否选择使用了EJB。如果你仅仅使用了Struts或其他的包含了J2EE特有APIs的framework,你会发现Spring关注了遗留下的问题,。 ◆Spring能消除在许多工程上对Singleton...... <阅读全文>
<!-- [post] -->

Spring面试:什么是Spring, 它有什么特点

<!--<span class="post-cat"><a href="http://www.mianwww.com/html/category/it-interview/spring" title="View all posts in Spring" rel="category tag">Spring</a></span>-->
<!-- [entry] -->
Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架。 ◆轻量——从大小与开销两方面而言Spring都是轻量的。完整的Spring框架可以在一个大小只有1MB多的JAR文件里发布。并 且Spring所需的处理开销也是...... <阅读全文>