繁体   English   中英

Spring Maven项目分裂,Eclipse中的部署问题

[英]Spring Maven project splitted, deployment issues in Eclipse

我有一个独立的Spring maven项目, myapp.web仅包含JSP和静态文件,而myapp.core包含应用程序上下文XML和控制器。

myapp.core

-src / main / resources / context.xml

-src / main / resources / 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可以正常工作。 但是,当通过“在服务器上运行”从Eclipse运行时, OpenSessionInViewFilter看不到sessionFactory中配置的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配置问题,因为它可以通过手动部署来工作,但是我无法修复它。 通常建议使用项目的构建路径,但不会成功。

谢谢

通过Eclipse运行应用程序时,请检查myapp.core中的xml文件是否在类路径中。 很有可能不是。 您可以使用类似的方法进行检查

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

问题可能是Eclipse配置为否,无法将xml文件复制到bin目录。

解决了。 问题是这样的:上下文正在自动重新加载(不确定原因)! myapp.core曾经是入口点(Web应用程序)。 拆分后,它在Project Facets上缺少一个称为Utility Project的刻度,并且Maven Integration for Eclipse并未将该项目部署为jar!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM