在整合spring,struts,hibernate框架时,犯了很多错,在解决了之后,现在再回头看自己整理的一些东西,倍感欣慰。不知道大家在整合ssh框架时都遇到过哪些问题,呵呵,写出来和大家分享一下,希望有所帮助。
1.Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext
导入spring-hibernation.jar bao
2.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;)
删除asm_2.3.jar
3.类名 is not mapped. (某个类没有映射)-------------->hql语句关于表名大小写错误
4.failed to lazily initialize a collection of role: com.stuclazz.entity.Clazz.students - no session or session was closed
即延迟加载错误,解决方法一:设置lazy=false
解决方法二:在web.xml中配置过滤器,代码如下
<filter>
<filter-name>myOpenSessionFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myOpenSessionFilter</filter-name>
r remove 'readOnly' marker from transaction definition
5. Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition
解决方法为:在添加时写上this.getHibernateTemplate().setFlushMode(2);
6.No bean specified ,解决方法为:在一对多的关系中,关于多的一方的实体类中对应的一的一方,未实例化。此时,只需实例化即可。
7.Unable to load configuration. - bean - jar:file:/C:/Tomcat%206.0/webapps/S2SH/WEB-INF/lib/struts2-core-2.1.6.jar!/struts-default.xml:68:140
在struts.xml中,引用的配置文件有误!应该是2.1版本的.例如:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
8.Error creating bean with name 'sessionFactory' defined in class path resource [spring.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext
解决方法:导入hibernate3.jar 覆盖之前的就可以了!
9. parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
解决方法:applicationContext.xml配置文件存在的位置找不到,将其移到src目录下即可,默认的classPath目录下,即在src目录下
10.No action instance for path /book could be created
(好久没整合ssh框架了,在整合s1sh框架时所遇到的问题,出现的原因是:在struts-config.xml文件中没有配置controller元素,即没有通知struts将拦截的请求交给spring context下的bean,所以在bean中配置的请求路径不能被创建!做如下配置即可:)
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
</controller>
11.java.lang.IllegalArgumentException: No bean specified
(没有bean被指定,在s1sh整合中,在form中构造实体的实例即可,即必须使用new实例)
12.Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: entity class not found: com.scce.TbBookInfo
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1336)
解决方法:重新使用hibernate reverse 生成一遍实体类,选对路径!
13.org.springframework.dao.InvalidDataAccessResourceUsageException: could not update: [com.scce.entity.TbBookInfo#9]; nested exception is org.hibernate.exception.DataException: could not update: [com.scce.entity.TbBookInfo#9]
现象描述:控制台将update语句打出,没问题。
解决方法:数据库中的字段容量设计的太小了。。。 亦或是,将插入数据的字段长度改小即可。
犯了一些很低级的错误,让大家见笑了。
分享到:
相关推荐
struts spring hibernate 登陆 SSH整合分页功能 SSH整合分页struts spring hibernate 登陆 SSH整合分页功能 SSH整合分页struts spring hibernate 登陆 SSH整合分页功能 SSH整合分页
本光盘是《整合Struts+Hibernate+Spring应用开发详解》一书的配书光盘,书中的代码按章存放, 即第二章所使用的代码放在codes文件夹的02文件夹下,依次类推。 本光盘根目录下有11个文件夹,其内容和含义说明如下: ...
Struts Spring Hibernate整合实践
使用mysql数据库的struts2 spring hibernate整合简单示例,也可参考我的:“struts2 spring hibernate整合要点、注意点”这篇文档来配置
Struts Spring Hibernate整合实践.doc
整合使用最新版本的三大框架(即Struts2、Spring4和Hibernate4),搭建项目架构原型。 项目架构原型:Struts2.3.16 + Spring4.1.1 + Hibernate4.3.6。 此外,还有:log4j、slf4j、junit4、ehcache等知识点。 项目...
struts2 spring hibernate 整合
struts spring hibernate整合
整合struts+hibernate+spring应用开发详解 李刚 第二到第四章
Struts技术资料 hibernate技术资料 spring技术资料 ssh整合技术(struts与hibernate整合,struts与spring整合,hibernate与spring整合,struts,hibernate,spring整合)
绝对详细的整合教材,值得你们拥有!!!目前流行的框架
Struts Spring Hibernate 整合教程
struts spring hibernate 整合实现方案
struts spring hibernate整合(二) struts spring hibernate整合(二)struts spring hibernate整合(二)
struts spring hibernate整合(三) struts spring hibernate整合(三) struts spring hibernate整合(三)
平台是:MyElipse5.1,Tomcat5.59,Struts1.1,Spring1.2,Hibernate3.0,Sql server2000.
struts spring hibernate 面试总结
Struts2 hibernate spring 整合案例