Spring Boot
ViewResolver
Annotations
HTTP Request Error
No Mapping Found

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

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

The error message stating no mapping found for an HTTP request URI is often blamed on ViewResolver, but mapping and view resolution are separate stages in Spring MVC. Mapping failure means Spring never reached the controller method, so view configuration is not the first suspect. A reliable fix comes from checking controller annotations, URL paths, template locations, and MVC setup order.

Understand Request Mapping Versus View Resolution

Spring handles a request in two major steps:

  • map request path to a controller method
  • resolve returned view name to a template

If the first step fails, you get no mapping found. ViewResolver only participates after a controller method returns a view name.

Minimal Working MVC Example

Use @Controller for HTML views and return logical view names.

java
1package com.example.web;
2
3import org.springframework.stereotype.Controller;
4import org.springframework.ui.Model;
5import org.springframework.web.bind.annotation.GetMapping;
6
7@Controller
8public class HomeController {
9
10    @GetMapping("/home")
11    public String home(Model model) {
12        model.addAttribute("message", "Spring MVC mapping works");
13        return "home";
14    }
15}

Template file should be at src/main/resources/templates/home.html when using Thymeleaf starter defaults.

Typical Thymeleaf Configuration

With Spring Boot starters, explicit resolver beans are often unnecessary. Keep configuration simple unless you need custom behavior.

properties
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false

If you define custom resolver beans, ensure they do not conflict with Boot auto-configuration.

Common Causes of No Mapping Found

Most incidents come from one of these:

  • controller package is outside component scan base package
  • used @RestController while expecting template rendering
  • method mapped to /home but request hits / or a different context path
  • wrong HTTP method, such as POST request to @GetMapping
  • custom servlet context path not reflected in request URL

Fast diagnostic step:

properties
logging.level.org.springframework.web=DEBUG

This logs handler mapping attempts and shows which paths were considered.

Verify Component Scan Scope

Spring Boot scans from the package of your main application class downward. If controllers live outside that tree, they are not discovered.

java
1package com.example;
2
3import org.springframework.boot.SpringApplication;
4import org.springframework.boot.autoconfigure.SpringBootApplication;
5
6@SpringBootApplication
7public class DemoApplication {
8    public static void main(String[] args) {
9        SpringApplication.run(DemoApplication.class, args);
10    }
11}

Place controllers under com.example... package hierarchy, or define explicit scan base packages.

When Manual ViewResolver Is Needed

If you render JSP on a traditional servlet container, manual resolver setup is common. For Thymeleaf in Boot apps, manual beans are rarely required.

java
1import org.springframework.context.annotation.Bean;
2import org.springframework.context.annotation.Configuration;
3import org.springframework.web.servlet.ViewResolver;
4import org.springframework.web.servlet.view.InternalResourceViewResolver;
5
6@Configuration
7public class WebConfig {
8
9    @Bean
10    public ViewResolver viewResolver() {
11        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
12        resolver.setPrefix("/WEB-INF/jsp/");
13        resolver.setSuffix(".jsp");
14        return resolver;
15    }
16}

Use this only when your template technology requires it.

End-to-End Test to Catch Mapping Errors Early

Add a lightweight MVC test to assert mapping and view resolution.

java
1import org.junit.jupiter.api.Test;
2import org.springframework.beans.factory.annotation.Autowired;
3import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
4import org.springframework.test.web.servlet.MockMvc;
5
6import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
7import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
8import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
9
10@WebMvcTest(HomeController.class)
11class HomeControllerTest {
12
13    @Autowired
14    private MockMvc mvc;
15
16    @Test
17    void homeShouldResolveView() throws Exception {
18        mvc.perform(get("/home"))
19           .andExpect(status().isOk())
20           .andExpect(view().name("home"));
21    }
22}

This prevents accidental mapping regressions during refactors.

Common Pitfalls

A common pitfall is configuring view resolvers repeatedly while the real issue is missing controller mapping. Another is mixing @RestController and view templates, which returns raw response bodies instead of resolving views. Teams also place templates in wrong directories or use mismatched suffix settings, causing secondary rendering errors after mapping is fixed. Finally, custom security rules can block routes and look like mapping failures unless logs are inspected carefully.

Summary

  • Mapping errors happen before view resolution, so debug controller routes first.
  • Use @Controller plus correct @GetMapping paths for template endpoints.
  • Keep controllers inside component scan scope.
  • Prefer Boot defaults for Thymeleaf unless custom resolver behavior is required.
  • Add MVC tests and web debug logs to catch URI mapping issues early.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design