Reputation: 412
I am developing spring boot application for learning.
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/views/");
resolver.setSuffix(".jsp");
registry.viewResolver(resolver);
}
I have configured my view resolver as given above. And below is the API endpoint for page
@RequestMapping(value = "/",method = RequestMethod.GET)
public ModelAndView homePage(){
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("index");
return modelAndView;
}
But when i hit this api, i am unable to get a response. I get 404
and error i get on console is
No mapping found for HTTP request with URI [/WEB-INF/views/index.jsp] in DispatcherServlet with name 'dispatcherServle
How can i fix this ?
Upvotes: 2
Views: 3482
Reputation: 1562
for people struggling with issues like this - the Spring Boot documentation states here that JSPs are not supported when running in embeddable servlet container - i.e. when using JAR packaging.
when using WAR packaging, the suggestion given in the answers here should work - but check that in the final WAR there is a directory at root: WEB-INF/views, with your JSPs
Upvotes: 2
Reputation: 630
the view path is wrong /WEB-INF/view/
instead /view/
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
registry.viewResolver(resolver);
}
or you can use the application.properties located in /resources/
instead
and add these properties
spring.mvc.view.prefix: /WEB-INF/views/
spring.mvc.view.suffix: .jsp
important: the jsp views should be in /resources/
directory
Upvotes: 0