简体   繁体   English

在Spring-Boot上找不到映射

[英]No mapping found on Spring-Boot

I'm new a spring-boot and spring framework. 我是新的spring-boot和spring框架。 According to me, web app create and deploy very easy with spring-boot but when i run my sample spring web app, application not found "welcome.html" page. 据我称,使用spring-boot可以很容易地创建和部署Web应用程序,但是当我运行示例Spring Web应用程序时,找不到该应用程序的“ welcome.html”页面。 I checked all similar question on stackoverflow and not worked me. 我检查了所有关于stackoverflow的类似问题,但没有成功。 I cannot see little issue but I didnt find my problem. 我看不到什么问题,但是我没有发现问题。 My application structure and codes are below: 我的应用程序结构和代码如下:

项目树png

MyApplication class is below: MyApplication类如下:

@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(MyApplication.class);
}

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

WelcomeController class is below: WelcomeController类如下:

@Controller
public class WelcomeController {

    @RequestMapping(value = "/welcome")
    public String welcome() {
        return "welcome"; //<- this is your login.html if it is directly in resource/templates folder
    }

}

application.properties file is below: application.properties文件如下:

spring.mvc.view.prefix = templates/
spring.mvc.view.suffix = .html
spring.mvc.static-path-pattern=/resources/**

WebMvcAppConfig class is below: WebMvcAppConfig类如下:

public class WebMvcAppConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        super.addViewControllers(registry); //To change body of generated methods, choose Tools | Templates.
        registry.addViewController("/welcome").setViewName("welcome.html");
    }

}

Firstly thanks a lot for quickly response my question @Andy Wilkinson and georges van. 首先,非常感谢您快速回复我的问题@Andy Wilkinson和georges van。 I looked for in spring boot reference guide and Serving Web Content with Spring MVC and I learned a lot of information about spring-boot. 我在Spring Boot参考指南和使用Spring MVC服务Web内容中寻找,并学到了很多有关spring-boot的信息。 I removed WebMvcAppConfig because this class not necessary for starter and removed SpringBootServletInitializer. 我删除了WebMvcAppConfig,因为对于初学者来说不需要该类,并删除了SpringBootServletInitializer。 I moved html files into templates as you say. 正如您所说,我已将html文件移动到模板中。 I keep simple and application run without issues. 我保持简单,应用程序运行没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM