我的 spring 项目在上下文根目录上的 tomcat 上正常工作'/'
,localhost:8080
但我试图将其更改为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
请指出我在哪里做错了。