NND, 项目移植报个No bean named 'sessionFactory' is defined

meiwenhui 2011-10-20 02:34:18
项目是SSH的架构,开发的时候是用的tomcat,并能正常运行,
但是移植到weblogic10上后,访问页面竟然出现:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:360)


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!--定义Spring的配置的位置,可以定义多个配置文件,可以使用通配符 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext*.xml</param-value>
</context-param>

<!--设置一起动当前的Web应用,就加载Spring,让Spring管理Bean-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring 刷新Introspector防止内存泄露 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>

<!-- 编码过滤 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>

<!--解决Hibernate延迟加载出现的问题,需要放到struts2过滤器之前-->
<filter>
<filter-name>lazyLoadingFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<!--Struts2的过滤器,使用Struts2,必须配置该项-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--解决Hibernate延迟加载出现的问题,仍需要放到struts2过滤器mapping之前-->
<filter-mapping>
<filter-name>lazyLoadingFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>





<session-config>
<session-timeout>30</session-timeout>
</session-config>
<!-- Struts Tag Library Descriptors -->
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/tlds/c.tld</taglib-uri>
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tlds/fn.tld</taglib-uri>
<taglib-location>/WEB-INF/tlds/fn.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tlds/fmt.tld</taglib-uri>
<taglib-location>/WEB-INF/tlds/fmt.tld</taglib-location>
</taglib>
</jsp-config>
<!--
<error-page>
<error-code>500</error-code>
<location>/500.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
-->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>

...全文
449 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhengyuyan 2012-10-31
  • 打赏
  • 举报
回复
怎么改啊,没看明白,在web.xml里加么?
dracularking 2011-10-21
  • 打赏
  • 举报
回复
哦照这么说启动时应该要初始化applicationContext.xml的,现在等于什么都没读进
meiwenhui 2011-10-20
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 dracularking 的回复:]

按常规是不应该停住的?貌似控制台启动时没报错了,一些配置文件都貌似初始化完成,然后访问页面时报错,那为什么仅是sessionFactory报出来,是因为只访问到sessionFactory还是什么其它,能尝试着让其它bean也报错吗
[/Quote]

搞定了,原因是weblogic10不识统配符(*)
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext*.xml</param-value>
</context-param>
改成
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</context-param>
在application.xml中import其它的就行了

dracularking 2011-10-20
  • 打赏
  • 举报
回复
按常规是不应该停住的?貌似控制台启动时没报错了,一些配置文件都貌似初始化完成,然后访问页面时报错,那为什么仅是sessionFactory报出来,是因为只访问到sessionFactory还是什么其它,能尝试着让其它bean也报错吗
meiwenhui 2011-10-20
  • 打赏
  • 举报
回复
这是控制台输出的信息, 在这里就Setting autowire strategy to name就停住了

Root WebApplicationContext: initialization started
[INFO ] 2011-10-20 00:24:08,540 method:org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:456)
Refreshing Root WebApplicationContext: startup date [Thu Oct 20 00:24:08 PDT 2011]; root of context hierarchy
[INFO ] 2011-10-20 00:24:08,737 method:org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:555)
Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1cfeda3b: defining beans []; root of factory hierarchy
[INFO ] 2011-10-20 00:24:08,764 method:org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:214)
Root WebApplicationContext: initialization completed in 469 ms
[INFO ] 2011-10-20 00:24:09,097 method:com.opensymphony.xwork2.util.logging.commons.CommonsLogger.info(CommonsLogger.java:42)
Parsing configuration file [struts-default.xml]
[INFO ] 2011-10-20 00:24:09,222 method:com.opensymphony.xwork2.util.logging.commons.CommonsLogger.info(CommonsLogger.java:42)
Parsing configuration file [struts-plugin.xml]
[INFO ] 2011-10-20 00:24:09,261 method:com.opensymphony.xwork2.util.logging.commons.CommonsLogger.info(CommonsLogger.java:42)
Parsing configuration file [struts.xml]
[INFO ] 2011-10-20 00:24:09,515 method:com.opensymphony.xwork2.util.logging.commons.CommonsLogger.info(CommonsLogger.java:42)
Setting autowire strategy to name
dracularking 2011-10-20
  • 打赏
  • 举报
回复
可以先确定一下这个错是在开始使用这个sessionFactory bean的时候报的错呢
还是框架开始初始化时报的错

如果是前者,看之前有没有使用过其它bean,如果没报错可以借鉴一下,如果没使用过...
但看信息报错更像是在一堆bean中找不到一个特定的,不像是更大范围的问题

如果是后者,那确定前两个bean已成功,也可以判断出些什么了,这个bean的一些相关信息是不是有误

话说异常堆栈信息少了点,只有两行
meiwenhui 2011-10-20
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 dracularking 的回复:]

可惜框架难以调试啊

按理这两个bean是不是已经成功读取了?

<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor" />

<bean id="oracleLobHandler" class="org.springfr……
[/Quote]
我想应该成功得到了,我们开发是在tomcat下,一直没问题, 移到weblogic10后,就启不来,报错.
dracularking 2011-10-20
  • 打赏
  • 举报
回复
可惜框架难以调试啊

按理这两个bean是不是已经成功读取了?

<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor" />

<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
<property name="nativeJdbcExtractor">
<ref bean="nativeJdbcExtractor" />
</property>
</bean>
zhu6100441 2011-10-20
  • 打赏
  • 举报
回复
包问题吧,weblogic找不到你注入的sessionFactory。应该是这个错误,没用过weblogic,但是曾经从tomcat移植到Jboss也报这错,最后发现是包冲突。
仙人长 2011-10-20
  • 打赏
  • 举报
回复
No bean named 'sessionFactory' is defined
你将问题的根原是于hibernate问题,测试hibernatea获取数据名称看hibernate那块具体报哪个错误
meiwenhui 2011-10-20
  • 打赏
  • 举报
回复
applicationContext.xml

<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor" />
<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
<property name="nativeJdbcExtractor">
<ref bean="nativeJdbcExtractor" />
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="lobHandler" ref="oracleLobHandler" />
<property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" />
</bean>

<context:component-scan base-package="com.hzunitech" />

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!--
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="manage*" propagation="REQUIRED" />
<tx:method name="get*" read-only="true" />
<tx:method name="search*" read-only="true" />
<tx:method name="*" read-only="true" />
-->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>

<tx:advice id="startProcess" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="startProcess"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution (* com.hzu.*.service..*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
</aop:config>

<bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" />
<bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
  • 打赏
  • 举报
回复
你应该贴applicationContext.xml。。web.xml看不出什么。。

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧