Java Tomcat赢得春季MVC冠军';无法打开Hello World html页面

Java Tomcat赢得春季MVC冠军';无法打开Hello World html页面,java,spring,spring-mvc,tomcat,Java,Spring,Spring Mvc,Tomcat,我试图打开一个简单的html页面,在localhost:8080/Hello上编写Hello world,但它在Spring MVC应用程序中。我用的是弹簧靴,它有自己的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/XMLSche

我试图打开一个简单的html页面,在localhost:8080/Hello上编写Hello world,但它在Spring MVC应用程序中。我用的是弹簧靴,它有自己的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_3_1.xsd"
         version="3.1">
    <display-name>Angular Rest Spring</display-name>

    <servlet>
        <servlet-name>angular</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>angular</servlet-name>
        <url-pattern>*</url-pattern>
    </servlet-mapping>
</web-app>
它找不到它。它说:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Sep 07 15:52:20 EEST 2016
There was an unexpected error (type=Not Found, status=404).
No message available

有什么想法吗?

如果您使用的是spring boot,则无需编写web.xml。Spring自动映射所有@Controller注释类,并从这些类中读取@RequestMapping注释

编写一个应用程序类:

package com.sample.web;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = "com.sample.web")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}
编写如下所示的控制器类:

package com.sample.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class HelloController {

    @RequestMapping("/hello")
    public String hello(Model model) {
        return "hello";
    }

}
并在src/main/resources/templates中编写一个模板html文件:

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Getting Started: Serving Web Content</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Hello
</body>
</html>

入门:提供Web内容
你好

我使用intellij,在其中我可以运行application类,该类将使hello页面在

上可用。就我而言,spring boot应用程序(使用maven)中的网页将进入:

src/main/resources/META-INF/resources/


此文件夹基本上相当于标准maven web应用程序中的src/main/webapp

使用、创建spring遗留项目或spring starter项目,它将配置

spring Boot?您可以分享您的spring上下文配置以及项目的结构吗?如果您在嵌入式Tomcat容器中运行spring boot应用程序,为什么需要一个web.xml?实际上,所有这些都可以在spring boot文档中找到:我知道这是可行的,但我想要一个不映射到工作的hello.html页面。例如,basic index.jsp不起作用。当我转到localhost:8080/它说page not foundit仍然找不到我的静态页面,但我使用spring boot,我希望为我的配置提供一个解决方案,而不是更改我的整个项目,谢谢
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Getting Started: Serving Web Content</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Hello
</body>
</html>