我已经搜索了互联网并调试了几个小时,但我一直在寻找问题所在。我有以下网络应用程序设置: Jetty 8.1.0.v20120127 Spring-orm 3.1.2.RELEASE Spring-web 3.1.2.RELEASE Hibernate-core 4.1.7-final
在通过 sessionFactoryBeanName init-param 定义的 web.xml 中:hibernateSessionFactory
虽然应用程序启动时没有错误并显示以下内容:
XmlWebApplicationContext:从 applicationContext.xml 加载一些 bean ClassPathXmlApplicationContext:从 applicationContext-hibernate.xml 加载一些 bean(也是 hibernateSessionFactory)
加载页面(请求)时,OpenSessionInViewFilter 激活并提供以下内容:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'hibernateSessionFactory' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1102)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:156)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:141)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:105)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1336)
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:172)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:267)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1336)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:483)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:521)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:412)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
at org.eclipse.jetty.server.Server.handle(Server.java:351)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:451)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:916)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:634)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:76)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:45)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534)
at java.lang.Thread.run(Thread.java:722)
在 DefaultListableBeanFactory.java:553 上进行调试时,beanDefinitionMap 显示了一个键集,其中只有加载了 XmlWebApplicationContext 的 bean。因此,没有显示文件 applicationContext-hibernate.xml 中的任何 bean。
bean 定义(LocalSessionFactoryBean 的设置器之一上的断点显示 bean 已创建):
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocations" ref="hibernateConfigLocations"/>
<property name="dataSource" ref="hibernateDatasource"/>
<property name="namingStrategy" ref="hibernateNamingStrategy"/>
<property name="hibernateProperties" ref="hibernateProperties"/>
我期待从 XmlWebApplicationContext 和 ClassPathXmlApplicationContext 中找到所有 bean。任何人都可以告诉我是什么导致了我的问题,如果缺少任何有关发现问题的信息,请告诉我?
网页.xml:
<display-name>webshop-cms</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>configuration</param-name>
<param-value>deployment</param-value>
</context-param>
<filter>
<filter-name>webshop-cms</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>nl.name.webshop.cms.CmsApplication</param-value>
</init-param>
<init-param>
<param-name>ignorePaths</param-name>
<param-value>/assets</param-value>
</init-param>
</filter>
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>hibernateSessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>webshop-cms</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
应用程序上下文.xml:
<context:component-scan base-package="nl.name.webshop.model" />
<context:component-scan base-package="nl.name.webshop.service" />
<context:component-scan base-package="nl.name.webshop.dao" />
<bean id="webshop.context" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list>
<value>classpath:applicationContext-hibernate.xml</value>
</list>
</constructor-arg>
</bean>
applicationContext-hibernate.xml:
<bean id="hibernateNamingStrategy" class="org.hibernate.cfg.DefaultComponentSafeNamingStrategy" />
<bean id="hibernateConfigLocations" class="java.util.ArrayList">
<constructor-arg>
<list>
<value>classpath:hibernate.cfg.xml</value>
</list>
</constructor-arg>
</bean>
<bean id="jndiDatasourceName" class="java.lang.String">
<constructor-arg value="java:comp/env/jdbc/webshop"/>
</bean>
<jee:jndi-lookup id="hibernateConfig" jndi-name="jdbc/webshop-hibernate-config"/>
<jee:jndi-lookup id="hibernateDatasource" jndi-name="jdbc/webshop-datasource"/>
<bean id="hibernatePropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties" ref="hibernateConfig"/>
</bean>
<bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
</bean>
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocations" ref="hibernateConfigLocations"/>
<property name="dataSource" ref="hibernateDatasource"/>
<property name="namingStrategy" ref="hibernateNamingStrategy"/>
<property name="hibernateProperties" ref="hibernateProperties"/>
</bean>