SSH一些出错小结

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

 

另外,如果报以下错:

Caused by: java.lang.SecurityException: class "org.objectweb.asm.CodeVisitor"'s signer information does not match signer information of other classes in the same package

也是由于上一个原因,即Spring 和 Hibernate 共用的一些 jar 文件发生了版本冲突,需要删除asm-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文件配置是否有错,大小写。。。

 

-----------------------------------------------------------------------------------------------

 

 

   %%%%Error Creating SessionFactory %%%%  java.lang.SecurityException: class"org.apache.commons.collections.SequencedHashMap"'s signer informationdoes not match signer information of other classes in the same package 
        因为我用的6.0.1,所以怎么也没出现这个异常。后来Google搜到很多人遇到了这个故障,猜测是commons-collections.jar的问题,可能和MyEclipse 6.0.0自带的包有问题导致。例如下面的是一个解决方案:http://ttitfly.iteye.com/blog/131955
        
        解决方案:
        1)下载 MyEclipse 6.0.1 来开发;
        2)或者去http://commons.apache.org/collections/ 下载一个新的包,把原来的commons-collections-xxx.jar给删了,然后用新的包替换。注意:一定要到应用的发布目录去做这个工作,而且替换后不能重新发布应用,然后立即重启Tomcat再测试。

--------------------------------------------------------------------------------------------------------

 

1、java.lang.NoSuchMethodError: org.springframework.util.ObjectUtils.nullSafeToString(Ljava/lang/Object;)Ljava/lang/String;
spring的jar包冲突错误:
我的是用的spring2.0的jar包,应为要用工作调度所以加了一个1.2版本的spring.jar做支持,项目跑在容器下跑没事,单元测试就会出现以上错误。
参考资料:http://www.iteye.com/post/365364
2、
support.DisposableBeanAdapter (DisposableBeanAdapter.java:148)     - Couldn't invoke destroy method of bean with name 'sessionFactory'
java.lang.IllegalStateException: Shutdown in progress
查了以下资料,也有人遇到过,找了一类似http://www.blogjava.net/allen-zhe/archive/2007/03/20/104880.html,我的解决方式,就在数据源配置那加了一个destroy-method="close"配置就可以了。
解决方法是看了http://forum.springframework.org/archive/index.php/t-19665.html这片文章想出来的。
3、org.hibernate.HibernateException: CGLIB Enhancement failed:
原因是myeclipse6.0的cglib-2.1.3.jar有bug,改为cglib-2.1.jar就可以了
4、[这个是在服务器运行时才报的,有点跑题了]还有一种比较隐蔽的错误,只要log4j属性文件设置为debug时才会报的错误代码如下:
DEBUG [main] xml.DefaultNamespaceHandlerResolver (DefaultNamespaceHandlerResolver.java:128)     - Ignoring namespace handler [org.springframework.scripting.config.LangNamespaceHandler]: handler class not found
java.lang.ClassNotFoundException: org.springframework.scripting.config.LangNamespaceHandler
找不到类的提示,在google上搜了一段时间没找到这个类在那个包里,最后一想肯定myeclipse自带的包肯定有,果然找到了,是少加载了spring-support.jar包。在myeclipse的Spring2.0 Misc Libraires库里
------------------------------------------------------------------------------------------------------------------
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值