Spring Hibernate在AOP方面的配置沖突
          Spring2.0 Hibernate3.1.x/Hibernate3.2

          在使用Spring的AOP編程時,會用到這幾個lib:
          asm-2.2.2.jar
          asm-commons-2.2.2.jar
          asm-util-2.2.2.jar

          Hibernate如果使用lib:
          asm.jar
          asm-attrs.jar

          其中asm-2.2.2.jar與asm.jar存在類上的沖突!!!
          使用其中之一或兩者都使用,可能會出現如下錯誤:
          java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor
          java.lang.NoClassDefFoundError: org/objectweb/asm/commons/EmptyVisitor
          java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit。。。。。。

          解決辦法是:
          1).去掉類路徑上的關于Hibernate的3個lib
          asm.jar
          asm-attrs.jar
          cglib-2.1.3.jar
          2).加入Spring中的以下4個lib
          asm-2.2.2.jar
          asm-commons-2.2.2.jar
          asm-util-2.2.2.jar
          cglib-nodep-2.1_3.jar

          如果再不行,都試試刪刪看。


          java.lang.SecurityException: class "javax.xml.bind.JAXBContext"'s signer information does not match signer information of other classes in the same package
          這個錯誤是因為載入的包里面有兩個相同路徑的類,就是在一個包里面有兩個同名的類
          有可能是將相同的包載入兩次或者把包解開后,先將jar文件載入了,后又將解開的類載入了


          Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
          試試自己去下一個spring的包,把包里的spring.jar加到項目里去。eclipse生成的時候可能會有些包沒有放進去。


          Error creating bean with name 'datasource' defined in file
          Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
          試試將commons-dbcp.jar,commons-pool.jar和commons- collections.jar加入CLASSPATH中


          hibernate 3.1 中的hibernateTemplate ,class應該為org.springframework.orm.hibernate3.HibernateTemplate,而非org.springframework.orm.hibernate.HibernateTemplate,因為某些原因我現在還用3.1,早前在玩springside的時候感覺hibernate 3.2 的Hibernate Annotations方便多了。

          找不到action或報錯的另一少有原因,一些版本hibernate版本會有些沖突方面的問題,可換一版本的hibernate試試,個人感覺hibernate的版本對應用會比較敏感


          org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in resource [/WEB-INF/dataAccessContext-hibernate.xml] of ServletContext: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
          java.lang.NoClassDefFoundError: javax/transaction/TransactionManager


          原因:缺少jta.jar 或者是找不到hbm.xml文件導致sessionfactory出錯,檢查hbm文件路徑是否正確,文件是否存在
          <property name="mappingResources">
            <list>
            <value>com/yourcompany/model/Login.hbm.xml
            </value>
            </list>
            </property>

          另外,此出錯也有可能是HBM文件里的錯誤引起,比如當初設計表的時候建立好了表間的約束關系,所以當生成其中一些持久化類,而另外一些有關聯的表沒有生成持久化類的時候。hbm文件里也會有生成相關的一對多多對一等的關聯,而另外的表沒有生成持久化類。所以運行時就會報這個錯誤。將HBM文件里暫時沒有使用到的配置刪除就可以了。


          2007-06-26 18:38:13,671 ERROR [com.yourcompany.model.dao.LoginDAO] - <save failed>
          org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not insert: [com.yourcompany.model.Login]; bad SQL grammar [insert into mysql__login (name, password) values (?, ?)]; nested exception is java.sql.SQLException: Table 'mysql.mysql__login' doesn't exist
          java.sql.SQLException: Table 'mysql.mysql__login' doesn't exist

          把hbm文件里面的catalog="'mysql"去掉即可!
          另注意的一點是eclipse生成的DAO文件應該是:
              public void save(Login transientInstance) {
                  log.debug("saving Login instance");
                  try {
                      getHibernateTemplate().save(transientInstance);
                      log.debug("save successful");
                  } catch (RuntimeException re) {
                      log.error("save failed", re);
                      throw re;
                  }
              }
          而不是原來的    public void save(LoginDAO transientInstance)

          只要在applicationContext.xml中加上
          <property name="mappingResources">
          <list>
          <value>com/yourcompany/hibernate/Users.hbm.xml</value>
          </list>
          </property>
          加這段代碼就會找不到action
          換一個版本的hibernate應該就ok


          Invalid path /addcustomer was requested
          輸入的路徑不正確,檢查spring中注冊的action的路徑和輸入的路徑是否一致,留意大小寫是否一致


          2007-08-08 15:36:17,406 ERROR [org.hibernate.proxy.BasicLazyInitializer] - CGLIB Enhancement failed: dao.User
          java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
           at net.sf.cglib.core.ClassEmitter.begin_class(ClassEmitter.java:77)

          Spring 和 Hibernate 共用的一些 jar 文件發生了版本沖突, 刪除 WEB-INF/lib/asm-2.2.3.jar 然后重啟 Tomcat.

          asm-2.2.3.jar
                 asm.jar
                 asm-attrs.jar
                asm-commons-2.2.3.jar
                asm-util-2.2.3.jar


          Resources cannot be null
          關于這個異常除了大家說的之外,如果在struts-config.xml的配置中不加載驗證插件,也是會報上述錯誤的,請在配置文件中加上
           <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"/> 
              <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
           <set-property property="pathnames"  value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
          </plug-in>


          hibernate java.lang.NullPointerException

          檢查一下配置文件。
          比如struts-config里,action的名稱和路徑是否一致,是否和spring里注冊的名字一致。特別留意大小寫。hbm文件配置是否有錯,大小寫。。。

          posted on 2007-06-21 12:01 lzj520 閱讀(1604) 評論(0)  編輯  收藏 所屬分類: Struts1Spring個人學習日記Hibernate
          主站蜘蛛池模板: 卓资县| 嵊泗县| 中牟县| 宾川县| 太康县| 会昌县| 板桥市| 南岸区| 班玛县| 绥芬河市| 蓝田县| 松滋市| 邻水| 玉溪市| 碌曲县| 崇礼县| 买车| 元谋县| 罗田县| 滕州市| 闻喜县| 藁城市| 红河县| 万源市| 满洲里市| 海安县| 榆林市| 荣昌县| 淮南市| 陇南市| 叙永县| 观塘区| 溧水县| 合水县| 敦化市| 汉寿县| 象州县| 湾仔区| 英超| 丰台区| 东丰县|