繁体   English   中英

为什么spring-ws在根上下文中声明时不会检测到spring配置文件。

[英]Why does spring-ws not detect a spring configuration file if declared in the root context.

我有一个奇怪的问题。 我有一个my-spring.xml文件我想添加到应用程序但由于某种原因我只能检测它是否在根上下文中。

以下内容未检测到根上下文中声明的my-spring.xml。

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
         version="2.4">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        /WEB-INF/my-datasources.xml
        /WEB-INF/my-spring.xml
        </param-value>
    </context-param>

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

    <servlet>
        <servlet-name>myservice</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/webservice-config.xml</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>myservice</servlet-name>
        <url-pattern>/webservice/*</url-pattern>
    </servlet-mapping>

    <mime-mapping>
        <extension>wsdl</extension>
        <mime-type>text/xml</mime-type>
    </mime-mapping>

    <mime-mapping>
        <extension>xsd</extension>
        <mime-type>text/xml</mime-type>
    </mime-mapping>

</web-app>

如果我将其更改为此然后它可以工作(请注意my-spring.xml位置的差异)。

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
         version="2.4">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        /WEB-INF/my-datasources.xml
        </param-value>
    </context-param>

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

    <servlet>
        <servlet-name>myservice</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/webservice-config.xml</param-value>
                <param-value>/WEB-INF/my-spring.xml</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>myservice</servlet-name>
        <url-pattern>/webservice/*</url-pattern>
    </servlet-mapping>

    <mime-mapping>
        <extension>wsdl</extension>
        <mime-type>text/xml</mime-type>
    </mime-mapping>

    <mime-mapping>
        <extension>xsd</extension>
        <mime-type>text/xml</mime-type>
    </mime-mapping>

</web-app>

我真的不明白我做错了什么。 如果我理解它的工作方式,当在根上下文中声明时(如第一个示例中所示),它应该由应用程序中的任何资源访问。 在本示例中似乎不是这种情况,因为我无法从Controller / Endpoint类访问my-spring.xml文件中定义的属性。

我认为你需要逗号分隔多个contextConfigLocation文件。 根据这个答案: https//stackoverflow.com/a/2725413/116509

编辑:尝试删除前面的/例如WEB-INF/my-datasources.xml而不是/WEB-INF/my-datasources.xml

尝试这样的事情

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:/my-datasources.xml
            classpath:/my-spring.xml
        </param-value>
</context-param>

但是你必须在classpath中拥有这两个文件

暂无
暂无

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

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