SSH集成常见问题。锦囊!谢谢大家把自己的错误以及解决方案贴出来。

  1. 云栖社区>
  2. 博客>
  3. 正文

SSH集成常见问题。锦囊!谢谢大家把自己的错误以及解决方案贴出来。

技术小美 2017-11-29 13:04:00 浏览716
展开阅读全文

1.  
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():  
原 因:<id>元素配置不正确,<id>元素缺少其子元 素<generator></generator>的配置。解决方法:<id>元素映射了相应数据库表的主键字段, 对其子元素<generator class="">,其中class的取值可以为increment、identity、sequence、hilo、native...... 等,一般取其值为native 。  
2.  
java.lang.IllegalArgumentException: id to load is required for loading  
方案:Users user=(Users)this.getHibernateTemplate().get(Users.class, id);如果以用户名为参数不能用此方法  
3.  
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query  
方案:sql语句有错误  
4.  
严重: Error starting static Resources  
java.lang.IllegalArgumentException: Document base D:/Program Files/Apache Software Foundation/Tomcat 5.0/webapps/tomcat-docs does not exist or is not a readable directory  
严重: Error in resourceStart()  
2007-6-6 23:32:25 org.apache.catalina.core.StandardContext start  
严重: Error getConfigured  
2007-6-6 23:32:25 org.apache.catalina.core.StandardContext start  
严重: Context startup failed due to previous errors  
2007-6-6 23:32:25 org.apache.catalina.core.StandardContext start  
严重: Exception during cleanup after start failed  
LifecycleException: Container StandardContext[/tomcat-docs] has not been started  
5.jsf+spring+hibernate  
严 重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener  
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool  
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool  
严重: Error listenerStart  
2007-6-8 10:31:55 org.apache.catalina.core.StandardContext start  
严重: Context [/shj01] startup failed due to previous errors  
2007-6-8 10:31:55 org.apache.catalina.core.ApplicationContext log  
方案:spring-framework-2.0.5/lib/jakarta-commons下的commons-collections.jar commons-dbcp.jar commons-pool.jar加载到工程去  
6.  
严重: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener  
javax.faces.FacesException: Can't parse configuration file:jar:file:/E:/工具/apache-tomcat-6.0.9/apache-tomcat-6.0.9/webapps /jsf02/WEB-INF/lib/jsf-impl.jar!/com/sun/faces/standard-html-renderkit.xml  
方案:把tomcat的安装文件换了位置就没事了  
7.spring MVC+hibernate  
严重: StandardWrapper.Throwable  
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 java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V  
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V  
方案:  
在使用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  
8.spring MVC+hibernate  
Exception in thread "main" org.springframework.dao.InvalidDataAccessResourceUsageException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update  
Caused by: org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update  
9.  
org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.transaction.interceptor.TransactionProxyFactoryBean] for bean with name 'userService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/framework/AbstractSingletonProxyFactoryBean  
Caused by: java.lang.NoClassDefFoundError: org/springframework/aop/framework/AbstractSingletonProxyFactoryBean 
方案:没加 spring 2.0 aop libraries  
10.  
org.apache.jasper.JasperException: Unable to compile class for JSP:  
方案:jsp网页中的java代码有问题  
11.  
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CompanyController' defined in class path resource [com/company/test/company-config.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'methodNameResolver' of bean class [com.company.action.CompanyController]: Bean property 'methodNameResolver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?  
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'methodNameResolver' of bean class [com.company.action.CompanyController]: Bean property 'methodNameResolver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?  


控制器没继承MultiActionController  

12.  


Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'turDiffService' defined in class path resource [com/expert/test/expert-config.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'turDifficultDao' of bean class [com.expert.operation.impl.TurDiffSerImpl]: Bean property 'turDifficultDao' is not writable or has an invalid setter method. Did you mean 'truDifficultDao'?  
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'turDifficultDao' of bean class [com.expert.operation.impl.TurDiffSerImpl]: Bean property 'turDifficultDao' is not writable or has an invalid setter method. Did you mean 'truDifficultDao'?  
原因:  
在定义时TurDifficultDao turDifficultDao ,把有个字母写错,后发现错误,改过来了,但没把get() set()方法中对应的改过来  

13.  

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'urlMapping' defined in class path resource [com/expert/test/expert-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '' is defined  
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '' is defined  


原因:  
在expert-config.xml中创建  
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">  
  <property name="mappings">  
  <props>  
    
  <prop key=""></prop>  
    
  </props>  
  </property>  
</bean>  
没有给<prop key=""></prop>赋值  

14.  

org.springframework.orm.hibernate3.HibernateQueryException: Instruction is not mapped  

[from Instruction]; nested exception is org.hibernate.hql.ast.QuerySyntaxException:  

Instruction is not mapped [from Instruction]  
Caused by: org.hibernate.hql.ast.QuerySyntaxException: Instruction is not mapped [from  

Instruction]  
原因:在data-config.xml中没加入<value>com/serializ/Instruction.hbm.xml</value>  
15.  

java.sql.SQLException: Field 'userId' doesn't have a default value  
原 因:把配置文件的主键改为<generator class="assigned" /> 可以进行自定义主键值,因为我在设主键时没有设成自动增长的,要求填默认值是受了配置文件里<generator class="native"/>的影响了。  

16.org.apache.jasper.JasperException: Unable to compile class for JSP  

原因:jsp页面中的java代码括号不对称!

 

1.   Spring2 aop库包冲突
 
异常信息如下所示:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V

Caused by:

java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V

 
解决方案:此错误是包冲突引起的,请删除WEB-INF/lib目录下的asm-2.2.3.jar文件,最后的修改MyEclipse 自带的spring2 aop库,以后就一劳永逸,如果已经发布了,则必须删除部署后的项目的WEB-INF/lib目录下的asm-2.2.3.jar文件,或者已发布的项 目,然后重新发布。

 

 
2.    Struts启动spring的插件初始化错误
 
错误信息如下:

[org.springframework.web.struts.ContextLoaderPlugIn]-[ERROR] Context initialization failed

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/action-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/action-servlet.xml]

Caused by:

java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/action-servlet.xml]

 
解决方案:根据错误信息知道,这个错误发生在插件初始化的时候。插件初始化时要读Spring的配置文件,因此插件的属性配置错误或者未配置都会引起这个错误。完整的配置如下(属性的值大家可以根据实际情况修改):

<plug-in

      className="org.springframework.web.struts.ContextLoaderPlugIn">

      <set-property property="contextConfigLocation"

        value="classpath*:applicationContext*.xml" />

   </plug-in>

 
找不到org/hibernate/cfg/HbmBinder$SecondPass
 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:/develop/apache-tomcat-5.5.27/webapps/test/WEB-INF/classes/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/HbmBinder$SecondPass

java.lang.NoClassDefFoundError: org/hibernate/cfg/HbmBinder$SecondPass

解决方案:删掉hibernate-annotations.jar

可能原因:版本问题 或者 和spring-hibernate.jar 冲突

 
AbstractEntityTuplizer引起的NullPointerException
 
错误信息如下:

java.lang.NullPointerException

       org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)

 
解决方案:cglib开头包只留下cglib-nodep-2.1_3.jar,其它的全部删除。

 

 

 

SSH整合常见错误与解决:

1org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myds' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool

 

2. java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor  

 

3. net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.SecurityException: class "com.wuwei.struts.bean.User$$EnhancerByCGLIB$$1016ffbf"'s signer information does not match signer information of other classes in the same package

 

4. java.lang.SecurityException: class "org.apache.commons.collections.SequencedHashMap"'s signer information does not match signer information of other classes in the same package

的错误。

 

1的解决办法是:

按常规方法搭建,可能会少两个包:commons-collections.jarcommons-pool.jar,手动加上即可;

 

2的解决办法是:

在使用SpringAOP编程时,会用到这几个lib
(版本不一样,文件名也不一样)
asm-2.2.3.jar
asm-commons-2.2.3.jar
asm-util-2.2.3.jar

Hibernate使用如下lib

asm.jar
asm-attrs.jar

其中asm-2.2.3.jarasm.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.
去掉类路径上的关于Hibernate3lib
asm.jar
asm-attrs.jar
cglib-2.1.3.jar
2.
加入Spring中的以下4
lib
asm-2.2.3.jar
asm-commons-2.2.3.jar
asm-util-2.2.3.jar
cglib-nodep-2.1_3.jar

从网上下一个最新的asm-all-3.0.jarjar包,然后把原来的所有asm开头的jar包全部删掉,还有一个cglib-2.1.3.jar也删掉.

 

3的解决办法是:

….hbm.xml文件中,将class标签的lazy属性改为false(默认为true)<class name="com.wuwei.struts.bean.User" table="user" lazy="false">。如果有schema="dbo" catalog="test"配置信息,请将其删除

 

4的解决办法是:

 

工程里的commons-collections.jar包与其它包不匹配导致的,例如如果你用commons-beanutils-1.7.0.jar,commons-collections-3.2.jar时会出现你的那种问题,如果是commons-beanutils-1.7.0.jar,commons-collections-3.1.ja









本文转自yunlielai51CTO博客,原文链接:http://blog.51cto.com/4925054/1060324,如需转载请自行联系原作者

网友评论

登录后评论
0/500
评论
技术小美
+ 关注