I'v started my journey with Spring Framework, can't get 1 simple thing done tho.
I start my server and go to localhost:8080/ - I got HTTP status 404 and I need to add project name to actually see my home page, so url is like localhost:8080/projectname - now it shows me home.jsp
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.company.projectname")
public class ApplicationConfig {
@Bean
ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/view/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
public class MvcDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
protected Class<?>[] getRootConfigClasses() {
return null;
}
protected Class<?>[] getServletConfigClasses() {
return new Class[] {ApplicationConfig.class};
}
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
@Controller
public class HomeController {
@GetMapping("/")
public String home(){
return "home";
}
}
Code is just a basic configuration, on top of that there is Spring Security configuration, but I really dont think that is relevant here.