Java DispatcherServlet不';开始

Java DispatcherServlet不';开始,java,spring,spring-mvc,servlets,Java,Spring,Spring Mvc,Servlets,当我使用Tomcat启动我的应用程序时,它只运行index.jsp,但当我试图从我的控制器()获取请求时,它会以404错误响应,比如DispatcherServlet没有启动 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/200

当我使用Tomcat启动我的应用程序时,它只运行index.jsp,但当我试图从我的控制器()获取请求时,它会以404错误响应,比如DispatcherServlet没有启动 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>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/dictionary</url-pattern>
    </servlet-mapping>
</web-app>
格雷德尔先生

plugins {
    id 'java'
}

group 'com.temp'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'

    compile 'org.springframework:spring-core:5.1.9.RELEASE'
    compile 'org.springframework:spring-context:5.1.9.RELEASE'
    compile 'org.springframework:spring-beans:5.1.9.RELEASE'
    compile 'javax.servlet:javax.servlet-api:4.0.1'
    compile 'org.springframework:spring-webmvc:5.1.9.RELEASE'
}

删除
并添加
,同时确保YOUR
@Controller
注释类位于正在扫描的包中。最后确保您调用的URL正确。我的操作与您编写和检查的URL完全一样,正确,但仍然存在相同的问题。您的应用程序部署为ROOT.war吗?如果不是,则url不正确。
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class App {
    @GetMapping("/home")
    public String getHome() {
        return "home";
    }
}
plugins {
    id 'java'
}

group 'com.temp'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'

    compile 'org.springframework:spring-core:5.1.9.RELEASE'
    compile 'org.springframework:spring-context:5.1.9.RELEASE'
    compile 'org.springframework:spring-beans:5.1.9.RELEASE'
    compile 'javax.servlet:javax.servlet-api:4.0.1'
    compile 'org.springframework:spring-webmvc:5.1.9.RELEASE'
}