Configure Viewresolver with Spring Boot and Annotations Gives No Mapping Found for Http Request with Uri Error

Configure ViewResolver with Spring Boot and annotations gives No mapping found for HTTP request with URI error

You only need to enable the default servlet, this is done by adding the following to your MvcConfiguration:

@Configuration
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter{
@Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/");
resolver.setSuffix(".html");
return resolver;
}

@Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}

Essentially what is happening is Spring does not know how to handle the handling of such content natively(could be a jsp say), and to this configuration is the way to tell it to delegate it to the container.

why im getting this error No mapping found for HTTP request with URI

My problem solved after adding this configuration

@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}

after adding this configuration white page error stopped but jsp page code started showing as html so added these two dependancies.

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>

this link helps

JSP file not rendering in Spring Boot web application

Spring Boot, Java Config - No mapping found for HTTP request with URI [/...] in DispatcherServlet with name 'dispatcherServlet'

OK! Found the problem.

This link helped me: https://samerabdelkafi.wordpress.com/2014/08/03/spring-mvc-full-java-based-config/

More specifically this configuration:

@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}

By setting a default handler, I would no longer get a white page but instead the JSP code as html, which clearly tells me that the JSP was being found but not rendered.

So the answer was on this page: JSP file not rendering in Spring Boot web application

I was missing the tomcat-embed-jasper artifact.

No mapping found for HTTP request with URI.... in DispatcherServlet with name

You could try and add an @Controller annotation on top of your myController Class and
try the following url /<webappname>/my/hello.html.
This is because org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping prepends /my to each RequestMapping in the myController class.



Related Topics



Leave a reply



Submit