eclipse - 导入不同项目的resources=applicationContext.xml时eclipse中的Tomcat抛出FileNotFoundException

标签 eclipse spring tomcat maven applicationcontext

我正在使用 Spring 和 Maven 项目。我在 mit-parent 下有项目 mit-webservices 和 mit-util 项目。

mit-webservices 正在使用 mit-utils。我正在从 mit-webservices 的 webapplicationContext.xml 中导入 mit-utils 的 applicationContext.xml,如下所示。

<import resource="classpath:mit/utils/shared/applicationContext.xml" />

但是当我在 Eclipse 中的 Tomcat 下运行 mit-webservices 时,我得到异常

Jun 23, 2012 2:35:50 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
Jun 23, 2012 2:35:50 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:vsm-webservices' did not find a matching property.
Jun 23, 2012 2:35:50 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jun 23, 2012 2:35:50 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jun 23, 2012 2:35:50 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 639 ms
Jun 23, 2012 2:35:50 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jun 23, 2012 2:35:50 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.25
Jun 23, 2012 2:35:51 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Jun 23, 2012 2:35:51 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Jun 23, 2012 2:35:51 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Sat Jun 23 14:35:51 PDT 2012]; root of context hierarchy
Jun 23, 2012 2:35:51 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [mit/webservices/webApplicationContext.xml]
Jun 23, 2012 2:35:51 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [mit/utils/shared/applicationContext.xml]
Jun 23, 2012 2:35:51 PM org.springframework.web.context.ContextLoader initWebApplicationContext
    SEVERE: Context initialization failed
    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:mit/utils/shared/applicationContext.xml]
    Offending resource: class path resource [mit/webservices/webApplicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [mit/utils/shared/applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [mit/utils/shared/applicationContext.xml] cannot be opened because it does not exist

在我的 mit-webservices 中有一些 junit 测试,我在其中加载 mit-webservices/webapplicationContext 文件并且它工作得很好。但是当我尝试在 tomcat 下部署 mit-webservices 时,它会抛出上述异常。

我还检查了 mit-webservices 的/lib 目录,发现 mit-utils.jar 确实存在。

每次部署前,我都会执行 mvn clean install 和 mvn eclipse:eclipse。 我认为 tomcat 在部署时无法在类路径中找到 mit-util,但我不知道为什么会这样。

我的WebApplicationContext.xml是

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util" xmlns="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">


    <import resource="classpath:mit/utils/shared/applicationContext.xml" />

    <context:component-scan base-package="mit" />

</beans>

我在 mit-webservices 中的 web.xml 是

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- Spring context -->

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:mit/webservices/webApplicationContext.xml </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>ServletAdaptor</servlet-name>
        <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>mit.webservices.jaxrs</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>ServletAdaptor</servlet-name>
        <url-pattern>/resources/*</url-pattern>
    </servlet-mapping>

</web-app>

谢谢

最佳答案

尝试不同的建议解决方案后。 我在部署程序集的 eclipse 中发现“找不到条目:mit-jpa”。所以我安装了 Eclipse WTP Eclipse 插件。然后重新部署 tomcat,一切正常。

关于eclipse - 导入不同项目的resources=applicationContext.xml时eclipse中的Tomcat抛出FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11173225/

相关文章:

eclipse - 如何在 Eclipse 向导中正确更新持续时间未知的操作的进度条?

java - 页面标题中每个命令的验证错误显示(Spring 3)

java - 通过ip限制tomcat访问

Java 网页开发 : Sessions are not saved between requests and a new JSESSIONID is created

java - Spring 运行的单元测试作为组失败,但单独通过

java - Subclipse 安装和设置

java - 简单的 Java 游戏崩溃

java - 使用 @ModelAttribute 时未显示自定义域对象

java - 带 @Secured 和 @PreAuthorize 注释的类不保护 super 方法

java - 部署到 Tomcat 7 OK 但无法访问应用程序