浏览 4196 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2014-05-06
最后修改:2014-05-06
使用的架构是Struts+Spring+JPA。 web.xml代码 <filter> <filter-name>Spring OpenEntityManagerInViewFilter</filter-name> <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class> <init-param> <param-name>entityManagerFactoryBeanName</param-name> <param-value>entityManagerFactoryaa</param-value> </init-param> </filter> <filter-mapping> <filter-name>Spring OpenEntityManagerInViewFilter</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> 以上代码,如果不配置entityManagerFactoryBeanName,默认查找Spring配置文件中<bean>id属性为entityManagerFactory,如果名称有变更,可以进行手动设置。 但是就算我配置了,也会报以下错误,提示无法找到。 org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactoryaa' is defined [color=red]一般会认为要么<bean>元素的ID写错了,或者没有导入相应的Spring配置文件,或者是该filter是在Spring容器启动之后进行加载,我首先加载的是Spring的listener,然后才是JPA的filter。 排除法: 1.试过更改名字,无效 2.新建一个Spring配置文件进行配置,然后在web.xml启动Spring配置文件时再进行引入,无效 疑惑: 查了源码,源码通过以下方式获取entityMnagerFactory WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); 然后使用wac.getBean()方法通过传递的id进行获取,entityManagerFactory对象。按理说,此处应该能获取到对象,但为什么会取不了? 公司的电脑以该配置都能正常运行,而家里却不能正常运行。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |