No mapping found on Spring-Boot

2019-08-25 06:03发布

I'm new a spring-boot and spring framework. 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. I checked all similar question on stackoverflow and not worked me. I cannot see little issue but I didnt find my problem. My application structure and codes are below:

project tree png

MyApplication class is below:

@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:

@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:

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

WebMvcAppConfig class is below:

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

}

1条回答
欢心
2楼-- · 2019-08-25 06:41

Firstly thanks a lot for quickly response my question @Andy Wilkinson and 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. I removed WebMvcAppConfig because this class not necessary for starter and removed SpringBootServletInitializer. I moved html files into templates as you say. I keep simple and application run without issues.

查看更多
登录 后发表回答