0

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

}
pyb
  • 4,813
  • 2
  • 27
  • 45
forever_software
  • 145
  • 1
  • 15
  • 2
    You almost never want `@EnableWebMvc` in a Spring Boot app. Also, `@SpringBootApplication` already enables component scanning for the package in which it's used, which is `net.samplespringboot` in this case. – Andy Wilkinson Dec 03 '17 at 20:06
  • 1
    @forever_software If your HTML page is static, you need none of what you've shared, other than your main application class. All you need to do is place your static files in `src/main/resource/static` and they will be served automatically by the static resource support that Spring Boot auto-configures. – Andy Wilkinson Dec 03 '17 at 20:08
  • 1
    move application.properties in src/main/resources not in that default package – AchillesVan Dec 03 '17 at 20:15

1 Answers1

0

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.

forever_software
  • 145
  • 1
  • 15