Spring容器在加载多个spring配置文件时查看错误的路径

时间:2016-10-03 09:29:50

标签: spring

我们在项目中使用Spring框架。我以下列方式从web.xml加载applicationContext文件:

<servlet>
        <servlet-name>SpringDispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/CustomerService/applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>SpringDispatcherServlet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

我正尝试以下列方式在JobDesigner-springintegration.xml文件中加载一个配置文件applicationContext

  <import resource="JobDesigner-springintegration.xml"/>    

现在,我正在尝试在

中加载更多配置文件
`JobDesigner-springintegration.xml`  file in the following manner:

<import resource="*.xml"/>

但奇怪的是,弹簧容器正在寻找下面的错误路径:  jndi:/localhost/cciupg/WEB-INF/CustomerService/ 日志摘录如下所示:

12:52:15,202 INFO  [STDOUT] 12:52:15,202 INFO  [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/CustomerService/JobDesigner-springintegration.xml]
12:52:15,453 INFO  [STDOUT] 12:52:15,448 WARN  [PathMatchingResourcePatternResolver] Cannot search for matching files underneath URL [jndi:/localhost/cciupg/WEB-INF/CustomerService/] because it does not correspond to a directory in the file system
java.io.FileNotFoundException: URL [jndi:/localhost/cciupg/WEB-INF/CustomerService/] cannot be resolved to absolute file path because it does not reside in the file system: jndi:/localhost/cciupg/WEB-INF/CustomerService/
    at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:205)
    at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52)
    at org.springframework.core.io.UrlResource.getFile(UrlResource.java:169)
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources(PathMatchingResourcePatternResolver.java:526)
    at org.springframework.web.context.support.ServletContextResourcePatternResolver.doFindPathMatchingFileResources(ServletContextResourcePatternResolver.java:92)
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:347)
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:279)
    at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1269)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:208)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:261)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:197)
    at org.springframework.beans.factory.xml.DefaultBeanDe

这里的问题是为什么spring容器正在查找错误的路径jndi:/localhost/cciupg/WEB-INF/CustomerService/而不是/WEB-INF/CustomerService/

奇怪的部分是为什么它将jndi:/localhost/cciupg附加到路径上?

1 个答案:

答案 0 :(得分:0)

WEB-INF不是我认为的类路径的一部分。因此无法找到您的* .xml文件。我相信jndi可能是Spring在查看类路径后抛出错误时检查的最后一个位置。

换句话说,尝试将文件放在类路径中。在java项目中,我经常看到主要的资源 - &gt;资源路径。