无法在spring中正确设置自定义上下文根

时间:2017-02-14 09:24:05

标签: java spring-mvc tomcat contextroot

我的spring项目在'/'的上下文根localhost:8080上正在tomcat上正常运行,但我正在尝试将其更改为localhost:8080/myroot,它给出错误。

我在谷歌搜索后做了以下更改。 在application.properties

中添加了src/main/resources
server.contextPath=/myroot
server.port=8080

但这不起作用。我刚刚添加了这个文件而没有改变任何其他内容。不知道是否要以某种方式与春天联系。

文件web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>Archetype Created Web Application</display-name>

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

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

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

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

    <!-- Spring Security -->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

启动tomcat时出现以下错误

org.springframework.web.servlet.FrameworkServlet.initServletBean Context initialization failed
 53  org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open Servlet    Context resource [/WEB-INF/dispatcher-servlet.xml]
dispatcher-servlet.xml而非/WEB-INF/

上搜索

/WEB-INF/spring

请指出我做错的地方。

0 个答案:

没有答案