我开始学spring,打不赢tomcat服务器。
这是 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<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>
</web-app>
this is dispatcher-servlet.xml
和主 Controller
package com.burmistrov;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class MainController {`
@GetMapping("/")
public String view() {
return "hello";
}}
And default settings of Tomcat
任何人都可以帮助我,我在哪里犯了错误?
最佳答案
在您的 web.xml
中,您没有配置 dispatcher-servlet.xml
。这就是你出错的原因。
将此代码添加到您的 web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/dispatcher-servlet.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
关于java - HTTP 状态 404 – 未找到 tomcat spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53907001/