我部署的时候出现一下错误,SSH整合时。就这问题已经纠结我一天了。麻烦大家帮帮忙..不要说asm2.23.jar给删了。我试过没用的。2011-12-06 14:12:21,375 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.hibernate.cfg.Configuration]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.hibernate.cfg.Configuration]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE
Caused by: java.lang.NoSuchFieldError: INSTANCE
以下是我的spring配置.我已经将hibernate交给spring管理了
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx" 
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 定义数据源 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>
</property>
<property name="url" >
<value>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Bank</value>
</property>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" >
<ref local="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/bank/bean/Loan.hbm.xml</value>
</list>
</property>
</bean>

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean> <bean id="dao" class="com.bank.daoInf.TransferDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>

<bean id="service" class="com.bank.serviceImpl.TransferServiceImpl">
<property name="dao">
<ref local="dao"/>
</property>
</bean>

<bean id="loanAction" class="com.bank.action.LoanAction" scope="prototype">
<property name="service" ref="service"></property>
</bean>
</beans>

解决方案 »

  1.   

    似乎你的web.xml配置有问题!代码贴出来!
      

  2.   

    web.xml配置了吗,没配的话不会加载你的配置文件的,类似这个<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:/applicationContext.xml,classpath*:/applicationContext-ws.xml,classpath*:/applicationContext-simple.xml,classpath*:/applicationContext-quartz.xml</param-value>
    </context-param>
      

  3.   


    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>SSH1</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
      
      <!-- spring-->
       <!-- 使用ContextLoaderListener初始化Spring容器 -->
      <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      
      <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/applicationContext.xml</param-value>
      </context-param>
       <!--spring结束-->
      
      <filter>
       <filter-name>Struts2</filter-name>
       <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
      </filter>
      <filter-mapping>
       <filter-name>Struts2</filter-name>
       <url-pattern>/*</url-pattern>
      </filter-mapping>  
      
      
      
      
     
    </web-app>
      

  4.   

    应该没问题吧?? web里的。
      

  5.   

    http://blog.csdn.net/cai5/article/details/6565523
    有心情就去看看 ,应该是配置文件有问题
      

  6.   

    是hibernate的数据源配置有问题?
      

  7.   


    应该不是吧..我把hibernate交给spring管理了的  
      

  8.   

    数据源没问题就看看jar包或jar包的版本吧!
      

  9.   

     hibernate-annotations.jar hibernate-commons-annotations.jar  这个包???有就删掉
      

  10.   


    已经删了。我晕。。现在就报另外一个错了org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [com.bank.daoImpl.TransferDaoImpl]: Bean property 'sessionFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
      

  11.   

    你的web.xml配置文件少了东西了
      

  12.   

    Hibernate 版本与 spring 版本不一致 估计是你的 hibernate版本低
      

  13.   

    <context-param>
            <param-name>contextConfigLocation</param-name>
            <paramvalue>classpath:配置文件的名字(如applicationContext.xml如果有多个的话可以applicationContext*.xml)</param-value>
        </context-param>
    还有中方式跟3楼说的一样!
      

  14.   

    不是web.xml错了..
    我是按照11楼兄弟的方法去做的..现在已经没报错了..谢谢..
    感谢大家为我回答问题.另外我问一下chenqi1988126你的QQ多少..我想加你请教一下别的问题。。
      

  15.   


    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
            <property name="sessionFactory">
                <ref local="sessionFactory"/>
            </property>
        </bean>lz我的配置中没有上面这个,你去掉试试,我看你没有配置事务处理策略,把那个加上看看<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <!--使用基于注解方式配置事务 -->
    <tx:annotation-driven transaction-manager="txManager"/>