收藏 分享(赏)

javaSSH框架错误解析.doc

上传人:j35w19 文档编号:7561937 上传时间:2019-05-21 格式:DOC 页数:29 大小:181KB
下载 相关 举报
javaSSH框架错误解析.doc_第1页
第1页 / 共29页
javaSSH框架错误解析.doc_第2页
第2页 / 共29页
javaSSH框架错误解析.doc_第3页
第3页 / 共29页
javaSSH框架错误解析.doc_第4页
第4页 / 共29页
javaSSH框架错误解析.doc_第5页
第5页 / 共29页
点击查看更多>>
资源描述

1、一 2二 SSH 架构易出现的问题之 Error creating bean with name * defined in file *.xml 2三 3四、SSH 常遇见问题,缺包 8五、Spring 的常见错误分析 10spring 的又一个问题 12六、SSH 整合项目中容易出现的错误整理 .13七、ssh2 框架易出现的错误 .17八、hibernate 面对几个错误的解决关键 .19一String hql=“from StationInfo a where a.stationCode like %“+stCode + “%“;注意:hql 中 StationInfo 不是对应数据库中

2、的表,而是对应值对象即:hibernate 的映射类文件,org.bean.StationInfo 类二 SSH 架构易出现的问题之 Error creating bean with name * defined in file *.xmlorg.apache.jasper.JasperException: Error creating bean with name indexall defined in file E:eclipseTomcat 5.5webappsfcWEB-INFbeans.xml : Error setting property values; nested excep

3、tion is org.springframework.beans.NotWritablePropertyException: Invalid property newsdao of bean class org.fc.classes.indexall: Bean property newsdao is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?这是一个很头痛的问题,基本解决方法有以下两种:1,如上

4、面提示在定义的 ACTION 方法里没写 GET,SET 方法或者是方法写的不规范解决方法:按如下编写看看能否解决.Beasn.xml 文件部分 /此文件是 SPRING 的配置文件/注册 indexall 这个 ACTION/newsdao 为此 ACTION 调用的 DAO 文件/注册 newsdao/最后必须在 userDAOProxy 中注册*Indexall 这个 ACTION 文件部分必须定义 newsdao 的 GET,SET 方法如下private Newsdao newsdao;public Newsdao getnewsdao()return newsdao;public

5、void setnewsdao(Newsdao newsdao)this.newsdao=newsdao;请大家注意下划线的变量,相同颜色的名字必须一致,不可有大小写错误! 2. TOMCAT 版本的问题 .本人一次用 TOMCAT5.0 编写,出现了上面的问题,结果是怎么都解决不了,后来换成了 TOMCAT5.5.就一点问题都没有了,所以第一种办法解决不了的请用此法看看,换个 TOMCAT 版本也许能解决问题 ,不过只对用 5.0 编写出问题有效哦.三1. org.hibernate.id.IdentifierGenerationException: ids for this class m

6、ust be manually assigned before calling save(): 原因: 元素配置不正确, 元素缺少其子元素的配置。解决方法: 元素映射了相应数据库表的主键字段,对其子元素,其中class 的取值可以为 increment、identity、sequence、hilo、native等,一般取其值为 native 。 2. java.lang.IllegalArgumentException: id to load is required for loading 方案:Users user=(Users)this.getHibernateTemplate().get

7、(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.IllegalArgumentExcepti

8、on: Document base D:Program FilesApache Software FoundationTomcat 5.0webappstomcat-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.Stand

9、ardContext 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 send

10、ing 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 bea

11、n 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

12、/shj01 startup failed due to previous errors 2007-6-8 10:31:55 org.apache.catalina.core.ApplicationContext log 方案:spring-framework-2.0.5libjakarta-commons 下的 commons-collections.jar commons-dbcp.jar commons-pool.jar 加载到工程去 6. 严重: Exception sending context initialized event to listener instance of cl

13、ass com.sun.faces.config.ConfigureListener javax.faces.FacesException: Cant 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 严重: Standard

14、Wrapper.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.ClassVisito

15、r.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-common

16、s-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.o

17、bjectweb.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.Inva

18、lidDataAccessResourceUsageException: 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.fact

19、ory.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.N

20、oClassDefFoundError: 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 JS

21、P: 方案: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

22、.beans.NotWritablePropertyException: Invalid property methodNameResolver of bean class pany.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.springfram

23、ework.beans.NotWritablePropertyException: Invalid property methodNameResolver of bean class pany.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? 控制器没继承 MultiActionCo

24、ntroller 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.NotWritableProp

25、ertyException: 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 tur

26、DifficultDao 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.s

27、pringframework.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

28、Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named is defined 原因: 在 expert-config.xml 中创建 没有给赋值 14. org.springframework.orm.hibernate3.HibernateQueryException: Instruction is not mapped from Instruction; nested exception is org.hibernate.hql.ast.QuerySyntaxExce

29、ption: Instruction is not mapped from Instruction Caused by: org.hibernate.hql.ast.QuerySyntaxException: Instruction is not mapped from Instruction 原因:在 data-config.xml 中没加入com/serializ/Instruction.hbm.xml 15. java.sql.SQLException: Field userId doesnt have a default value 原因:把配置文件的主键改为 可以进行自定义主键值,因

30、为我在设主键时没有设成自动增长的,要求填默认值是受了配置文件里的影响了。 16.org.apache.jasper.JasperException: Unable to compile class for JSP 原因:jsp 页面中的 java 代码括号不对称!17.Error creating bean with name sessionFactory 网友回复:Error creating bean with name sessionFactory 网友回复: UserDAO 这个 java Bean 有问题, 导致 : 严重: action: null 再试试, 有可能是 没有符合 j

31、avabean 的规则 网友回复:spring 的配置文件有错误 网友回复:UserDAO 是自动生成的,spring 配置肯定没问题啊网友回复:我遇到的问题跟你遇到的一模一样,我到现在也还没能解决出来,如果你解决了希望能告诉一下。非常感谢网友回复:RP网友回复:看错误信息,似乎是 java bean 里的 setter 方法不正确。建议检查一下。网友回复:Caused by: java.lang.NoClassDefFoundError:org/apache/commons/pool/impl/GenericObjectPool 是一些包没有加载进去吧 eclipse 是数据字典的方式加载的

32、 ,放到 tomcat 中要重新引用网友回复:我在上面写到跟你出的问题大概差不多,我现在我的问题已经解决掉了,我在service 类修改了一下,我的 service 是不是用工具生成的,我的错误是 service 继承了hibernateDaoSupport 类,粗心造成的网友回复:我也遇到这个错误了,不过在网上终于找到了答案,你这个是一个包没有导入进去, 除了需要 commons-dbcp-1.2-1.jar 之外还需要 commons-pool.jar 这个包,把后面这个 commons-pool.jar 包导入进去就应该行了,我的是这样解决的 四、SSH 常遇见问题,缺包现象 1:org

33、.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.aop.support.DefaultPointcutAdvisor defined in null: Cant resolve reference to bean txAdvice while setting property advice; nested exception is原因:缺少 Spring 开头的各种包,到 Spring2.0 src 中编译新的 dist 目录出来,拷贝

34、全部的springxxx.jar 到 jpetstore/WEB-INF/lib 下。OK。现象 2: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.NoClass

35、DefFoundError: javax/transaction/TransactionManagerjava.lang.NoClassDefFoundError: javax/transaction/TransactionManager原因:缺少 jta.jar,OK现象 3:java.lang.NoClassDefFoundError: org/dom4j/Attribute缺 dom4j.jarjava.lang.NoClassDefFoundError: net/sf/ehcache/CacheException缺 ehcache.jarjava.lang.NoClassDefFoun

36、dError: net/sf/cglib/core/KeyFactory缺 cglib-full.jar现象 4:org.springframework.beans.factory.BeanCreationException: Error creating bean with name sessionFactory defined in resource /WEB-INF/dataAccessContext-hibernate.xml of ServletContext: Initialization of bean failed; nested exception is net.sf.hib

37、ernate.MappingException: could not instantiate id generatornet.sf.hibernate.MappingException: could not instantiate id generator原因:hbm 中 id 字段的定义为没有定义的 sequesce,修改为 inc/ 原来是 sequence.这样就可以了。现象 6:org.springframework.beans.factory.BeanCreationException: Error creating bean with name /shop/addItemToCar

38、t.do defined in ServletContext resource /WEB-INF/petstore-servlet.xml: Cant resolve reference to bean petStore while setting property petStore; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named petStore is definedorg.springframework.beans.factory.NoSu

39、chBeanDefinitionException: No bean named petStore is defined原因:我使用 Struts 作为 action,当然就不需要使用 Spring WEB framework,因此也不需要与之配套的配置文件例如,petstore-servlet.xml,还有 remote-servlet.xml ,但是 Spring 仍旧加载此两个文件,没办法,只好将此两个文件挪动到别的地方,但是又出现找不到这两个文件的 IO 异常,没办法,只好又拷贝回来,然后把文件内容晴空。终于好用了。原因就是,只要你在 web.xml 中定义了这个 servlet,他就

40、要去找此 servlet 名字对应的配置文件(servletname-servlet.xml),找不到就出错。ok,现在注释掉 web.xml 中名字为 petstore的 servlet 定义和影色,删除 petstore-servlet.xml 文件,哈哈,这下不报告错误了。同理,注释名字为 remote 的 servlet,删除 remote-servlet.xml 后,重新启动 tomcat,这下不报告任何错误了。呵呵。原来如此啊。现象:java.lang.NullPointerExceptionsrx.test.testhibernate.UserDAO.getAll(UserDAO

41、.java:9)srx.test.struts.action.UserAction.execute(UserAction.java:20)原因:Action 原来UserDAO / 这个类 OKpublic class UserDAO extends HibernateDaoSupport public List getAll() return this.getHibernateTemplate().find(“select aa from Account aa“);/这个类需要修改public class UserAction extends ActionSupport UserDAO da

42、o = new UserDAO(); List accounts = dao.getAll();。 。 。修改:/UserDAO dao = new UserDAO(); WebApplicationContext wac = this.getWebApplicationContext();UserDAO dao = (UserDAO) wac.getBean(“userDAO“);OK五、Spring 的常见错误分析现象 1:org.springframework.beans.factory.BeanCreationException: Error creating bean with na

43、me org.springframework.aop.support.DefaultPointcutAdvisor defined in null: Cant resolve reference to bean txAdvice while setting property advice; nested exception is 原因:缺少 Spring 开头的各种包,到 Spring2.0 src 中编译新的 dist 目录出来,拷贝全部的springxxx.jar 到 jpetstore/WEB-INF/lib 下。OK。 现象 2:org.springframework.beans.fa

44、ctory.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/TransactionManagerjava.lang.NoClassDefFoundErr

45、or: javax/transaction/TransactionManager 原因:缺少 jta.jar,OK现象 3:java.lang.NoClassDefFoundError: org/dom4j/Attribute 缺 dom4j.jarjava.lang.NoClassDefFoundError: net/sf/ehcache/CacheException缺 ehcache.jarjava.lang.NoClassDefFoundError: net/sf/cglib/core/KeyFactory缺 cglib-full.jar现象 4:org.springframework.

46、beans.factory.BeanCreationException: Error creating bean with name sessionFactory defined in resource /WEB-INF/dataAccessContext-hibernate.xml of ServletContext: Initialization of bean failed; nested exception is net.sf.hibernate.MappingException: could not instantiate id generatornet.sf.hibernate.M

47、appingException: could not instantiate id generator原因:hbm 中 id 字段的定义为没有定义的 sequesce,修改为 incname=“id“type=“string“column=“userid“/ 原来是 sequence. 这样就可以了。现象 6:org.springframework.beans.factory.BeanCreationException: Error creating bean with name /shop/addItemToCart.do defined in ServletContext resource /WEB-INF/petstore-servlet.xml: Cant resolve reference to bean petStore while setting

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报