报错如下
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Unsatisfied dependency expressed through bean property 'eventListeners': : Error creating bean with name 'tm' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tm' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1150)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1040)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:545)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:196)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:987)
ApplicationContext.xml如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:p="http://www.springframework.org/schema/p" 
   xmlns:aop="http://www.springframework.org/schema/aop" 
   xmlns:tx="http://www.springframework.org/schema/tx" 
   xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
       http://www.springframework.org/schema/aop 
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "
       default-autowire="byType">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<property name="url"
value="jdbc:sqlserver://localhost:1433;databaseName=Test">
</property>
<property name="username" value="sa"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/product/entity/Product.hbm.xml</value></list>
</property>
</bean>

<bean id="tm" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

<tx:advice id="txAdvice" transaction-manager="tm">
<tx:attributes>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut expression="execution(* com.product.biz.*.*(..))" id="cutPoint"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="cutPoint"/>
</aop:config>


<bean id="ProductDAO" class="com.product.dao.ProductDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

<bean id="ProductBIZ" class="com.product.biz.ProductBIZ"/>
<bean id="CheckAction" class="com.product.web.CheckAction"/>
</beans>这是神马问题呀!!

解决方案 »

  1.   

     applicationContext.xml(/WEB-INF/applicationContext.xml)<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"><beans>
       <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
         <property name="driverClassName" value="org.gjt.mm.mysql.Driver" />
         <property name="url" value="jdbc:mysql://localhost:3306/stud"/>
         <property name="username" value="root" />
         <property name="password" value="root" />
       </bean> 
       <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
         <property name="dataSource" ref="dataSource" />
         <property name="hibernateProperties">
          <props>
           <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
           <prop key="hibernate.show_sql">true</prop>
          </props>
         </property>
         <property name="mappingResources">
          <list>
           <value>com/ex/model/Employee.hbm.xml</value>
          </list>
         </property>
       </bean>
     
     <bean id="employeeDao" class="com.ex.dao.impl.EmployeeDaoImpl">
      <property name="sessionFactory" ref="sessionFactory" />
     </bean> <bean id="employeeManager" class="com.ex.service.impl.EmployeeManagerImpl">
      <property name="employeeDao" ref="employeeDao" />
     </bean>
     
     <bean id="addBean" class="com.ex.action.EmployeeAction" scope="prototype">
      <property name="employeeManager" ref="employeeManager" />
     </bean> <bean id="editBean" class="com.ex.action.EmployeeAction" scope="prototype">
      <property name="employeeManager" ref="employeeManager" />
     </bean>
     
     <bean id="updateBean" class="com.ex.action.EmployeeAction" scope="prototype">
      <property name="employeeManager" ref="employeeManager" />
     </bean>
      
     <bean id="deleteBean" class="com.ex.action.EmployeeAction" scope="prototype">
      <property name="employeeManager" ref="employeeManager" />
     </bean>
     
     <bean id="saveOrUpdateBean" class="com.ex.action.EmployeeAction" scope="prototype">
      <property name="employeeManager" ref="employeeManager" />
     </bean>
     
     <bean id="listBean" class="com.ex.action.EmployeeAction" scope="prototype"> 
      <property name="employeeManager" ref="employeeManager" />
     </bean>  <bean id="loginBean" class="com.ex.action.EmployeeAction" scope="prototype">
      <property name="employeeManager" ref="employeeManager" />
     </bean>
     
     </beans>
      

  2.   

    如果你的applicationContext.xml在web-inf下
    那么在web.xml上因该有
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    classpath:applicationContext.xml
    </param-value>
    </context-param>
      

  3.   

    可能原因:1. spring与hibernate的冲突.两个框架都依赖asm.jar包spring的版本是asm-2.23.jar.hibernate依赖的是asm.jar 
    需要将asm-2.2.3.jar删除.没有删除的话会引起这样的异常 
    2. hibernate与struts的冲突,两个框架都依赖common-collections.jar.hibernate的是common-collections-2.1.1.jar,struts的是common-collections.jar.需要将hibernate所依赖的common-collections-2.1.1.jar删除.没有删除的话会引起这个异常 
    3. web.xml中没有配置
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
            /WEB-INF/applicationContext*.xml,classpath*:applicationContext*.xml
      </param-value>
     </context-param>
     <listener>
      <listener-class>
       org.springframework.web.context.ContextLoaderListener
      </listener-class>
     </listener>
    5. jar包导入是否正确
    Spring包(9个): 
    commons-dbcp.jar、commons-pool.jar、spring.jar、spring-beans.jar、 
    spring-context.jar、spring-core.jar、spring-dao.jar、 
    spring-hibernate3.jar、spring-web.jar。 struts2.0包(6个):commons-logging-api-1.1.jar、freeer-2.3.8.jar 
    ognl-2.6.11.jar、struts2-core-2.0.8.jar、 
    struts2-spring-plugin-2.0.11.2.jar、xwork-2.0.3.jar hibernate包:myeclipse工具自动添加生成导入。 
    还有就是数据库驱动包。