2014-06-10 30 views
0

我有一个分开的Spring Maven项目,myapp.web仅包含JSP和静态文件,而myapp.core包含应用上下文XML和控制器。Spring Maven项目拆分,Eclipse中的部署问题

myapp.core

- 的src /主/资源/ context.xml中

- 的src /主/资源/ MVC-context.xml中

myapp.web

- src/main/webapp/WEB-INF/web。 XML

web.xml中包含根上下文配置和servlet配置

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath*:/context.xml</param-value> 
</context-param> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
    ... 

<servlet> 
    <servlet-name>servlet0</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>classpath*:/mvc-context.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>servlet0</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

我也有OpenSessionInViewFilter配置

<filter> 
    <filter-name>hibernateFilter</filter-name> 
    <filter-class> 
     org.springframework.orm.hibernate3.support.OpenSessionInViewFilter 
    </filter-class> 
    <init-param> 
     <param-name>flushMode</param-name> 
     <param-value>AUTO</param-value> 
    </init-param> 

</filter> 
<filter-mapping> 
    <filter-name>hibernateFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

现在,生成从myapp.web战争和Tomcat的滴手动工作正常。 但是,当通过“Run On Server”从Eclipse运行时,OpenSessionInViewFilter没有看到在context.xml中配置的sessionFactory 我尝试修复项目的构建路径,但它不会运行。

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1094) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:276) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1079) 
    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:242) 
    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:227) 
    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:171) 

现在我知道这是一个的Eclipse/M2E-WTP配置问题,因为它的工作通过手动部署,但我已经无法修复它。按照通常建议的方式与项目的构建路径一起玩,但没有成功。

感谢

回答

0

已解决。 问题是这样的:上下文是自动重新加载(不知道为什么)! myapp.core曾经是入门点(网络应用程序)。分裂后,它有一个缺少的勾号项目方面称为实用项目,Maven Integration for Eclipse没有将此项目作为jar部署!

0

检查中myapp.core的XML文件是在类路径当您运行通过Eclipse应用程序。他们很可能不是。 您可以通过使用一些检查像

if (getClass().getResource("my context-xml file") ! = null) { 
    System.out.println("No context file on the classpath, won't work"); 
} 

问题可能是,Eclipse是没有配置到XML文件复制到bin目录。

+0

谢谢,但找到了上下文,因为它没有显示任何'FileNotFoundException'。问题是'OpenSessionInViewFilter'没有看到'context.xml'中的'sessionFactory'。 – isah