java 不寻常的问题 No bean named 'sessionFactory' is defined 和 initialize a collection of role
左右java的“No bean named 'sessionFactory' is defined ” 现在经常出去SHH或在其框架内Sping+JPA使用底部HIbernate annotation 的实现;出现异常的原因是找不到sessionFactory bean.
原因有例如以下:
1、在Many-to-one 或是many-to-many 时候 我们设置了fetchType=“lazy” 延时载入。
解决这个问题的方法在web.xml中,增加 openSessionInView过滤器 ,OpenSessionInViewFilter的主要功能是用来把一个Hibernate Session和一次完整的请求过程相应的线程相绑定。目的是为了实现"Open Session in View"的模式。
比如:它同意
在事务提交之后延迟载入显示所须要的对象。
OpenSessionInViewFilter 过滤器将 Hibernate Session 绑定到请求线程中,它将自己主动被 Spring 的事务管理器探測到。所以 OpenSessionInViewFilter 适用于 Service 层使
(当中的filter-class 注意对号入座 我使用的是Hibernate 所以filter-calss :<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
假设你用的是JPA:<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
)
<!-- 用于处理延时载入问题 openSessionInView过滤器,该过滤器必须在struts过滤器之前配置-->
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2、尽管前面已经增加了OpenSessionInViewFilter 。可是也能够是报出sessionFactory not defited;
原因非常easy————名称不匹配,OpenSessionInViewFilter模式使用Bean.xml 里面id="sessionFactory "的Bean 。这时假设你的sessionfactory Bean 不叫做这个名,它自然报出Bean 找不到;
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
版权声明:本文博主原创文章,博客,未经同意不得转载。
java 不寻常的问题 No bean named 'sessionFactory' is defined 和 initialize a collection of role的更多相关文章
- No bean named 'sessionFactory' is defined
1.错误叙述性说明 严重:Servlet service() for servlet default threw exception . org.springframework.beans.facto ...
- 解决BeanNotOfRequiredTypeException: Bean named 'XXX' must be of type XXX, but was actually of type XXX问题
Java新手,困扰了一下午. 发布时总是报这样一个错误. org.springframework.beans.factory.BeanCreationException: Error creating ...
- No bean named 'transactionManager' is defined
2016-10-20 23:27:17.771 INFO 7096 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped &quo ...
- No bean named 'hibernateTemplate' is defined
1.错误描述 WARN:2015-05-01 15:42:22[localhost-startStop-1] - Exception encountered during context initia ...
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager'
1.错误描述 五月 01, 2015 2:12:31 下午 org.hibernate.validator.util.Version <clinit> 信息: Hibernate Vali ...
- Spring错误之org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'bookService' is expected to be of type 'pw.fengya.tx.BookService' but was actually of type 'com.sun.proxy.$Proxy1
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cas ...
- Bean named '...' is expected to be of type [...] but was actually of type [com.sun.proxy.$Proxy7解决方法
报错 三月 07, 2017 8:09:52 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepare ...
- Springboot2.x 启动报错:Bean named 'xxxService'... but was actually of type 'com.sun.proxy.$Proxy82'
Springboot 2.0.5 搭建一个新项目启动后报错:Bean named 'xxxService'... but was actually of type 'com.sun.proxy.$Pr ...
- Spring Security使用报错 No bean named 'springSecurityFilterChain' is defined
今天配置spring security时,运行报出No bean named 'springSecurityFilterChain' is defined错误,报错信息如下 严重: Exception ...
随机推荐
- POJ 2538 WERTYU水的问题
[题目简述]:题意非常easy,没有trick. [分析]:事实上这题还是挺有趣的,在 算法竞赛入门经典中也有这一题. 详见代码: // 120K 0Ms /* 边学边做 -- */ // 字符串:W ...
- uml 9图不同的角度品种分类
只要阅读uml视频后为其9一些模糊样图或理解.话又说回来后来他们自己的系统看着笔记,统的了解.以下分别从两个不同的角度对uml中9种图进行理解以及当中某些图的区分,本人比較菜,有些不完好的地方欢迎提出 ...
- 安装Microsoft .NET Framework 3.5 Service Pack 1回报1603错
server升级了一下系统补丁(360安装),所有发现.net无法打开网站,提示" 因为无法创建应用程序域,因此未能运行请求.错误: 0x80070002 系统找不到指定的文件. " ...
- android性能测试内存泄漏
1.什么是内存泄漏? 适用于该系统的内存使用内存泄漏,未回复(释放),该内存可以没有事业,也不能被其他人使用使用自己. 2.出有什么差别? 内存泄漏是分配出去的内存无法回收. 内存 ...
- 如何区分MNO和MVNO
MVNO(Mobile Virtaul Network Operator)虚拟网络运营商,没有自己的物理网络,租用MNO(Mobile Network Operator)网络提供的网络服务. 我们知道 ...
- Performance Monitor采集性能数据
Performance Monitor采集性能数据 Windows本身为我们提供了很多好用的性能分析工具,大家日常都使用过资源管理器,在里面能即时直观的看到CPU占用率.物理内存使用量等信息.此外新系 ...
- Java下拼接执行动态SQL语句(转)
在实际业务中经常需要拼接动态SQL来完成复杂数据计算,网上各类技术论坛都有讨论,比如下面这些问题: http://bbs.csdn.net/topics/390876591 http://bbs.cs ...
- java代码 分解EXCEL(一)
一,service层接口定义: ExcelParseService.java 一,service层接口实现: ExcelParseServiceImpl.java watermark/2/text/a ...
- Eclipse建筑物SSH(struts-2.2.3 + spring-2.5.6 + hibernate-3.6.8)相框-随着源代码
一直想自己搭建一个ssh框架,这次因为编写demo的须要,就亲手搭建了一下,并逐步測试!以下进入正题: 创建Struts项目 整合步骤: 1,在Eclipse中创建一个DynamicWeb Proje ...
- Android ELF文件格式
最近一直在学习elf相关信息.一个小总结,这里记录,也方便以后查阅. ELF是类Unix类系统,当然也包含Android系统上的可运行文件格式(也包含.so和.o类文件). 能够理解为Android系 ...