繁体   English   中英

在Spring-Boot上找不到映射

[英]No mapping found on Spring-Boot

我是新的spring-boot和spring框架。 据我称,使用spring-boot可以很容易地创建和部署Web应用程序,但是当我运行示例Spring Web应用程序时,找不到该应用程序的“ welcome.html”页面。 我检查了所有关于stackoverflow的类似问题,但没有成功。 我看不到什么问题,但是我没有发现问题。 我的应用程序结构和代码如下:

项目树png

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类如下:

@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文件如下:

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

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");
    }

}

首先,非常感谢您快速回复我的问题@Andy Wilkinson和georges van。 我在Spring Boot参考指南和使用Spring MVC服务Web内容中寻找,并学到了很多有关spring-boot的信息。 我删除了WebMvcAppConfig,因为对于初学者来说不需要该类,并删除了SpringBootServletInitializer。 正如您所说,我已将html文件移动到模板中。 我保持简单,应用程序运行没有问题。

暂无
暂无

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

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