Scrivio Interview library
DebuggingIntermediate6 min read · updated 12 November 2026

Startup fails with 'Ambiguous mapping. Cannot map method ... There is already ... bean method mapped'. What causes this and how do you find the conflict?

The error means two handler methods were registered with exactly the same mapping: the same path, the same HTTP method and the same params, headers, consumes and produces conditions. It is usually caused by a copied controller that kept its paths, or by two beans of the same controller class. The message names both methods, so we compare their full conditions, make them distinct or remove the duplicate; adding a different condition such as produces or params makes the mappings legitimately separate, and the mappings actuator endpoint lists every mapping once the application starts.

Why this question is asked

Unlike most mapping problems, this one stops the application from starting at all, which is good: Spring found a real conflict and refused to guess. Interviewers ask about it because the fix is quick once we read the message properly, and the root causes, copied code and duplicate beans, say something about how the project is organized. In this answer, we will read the error, see when Spring raises it, find the usual causes, make mappings distinct where both are wanted, and use the tools that list all mappings.

1Reading the Error

The exception is thrown while RequestMappingHandlerMapping registers handler methods at startup. A typical message looks like this.

Java
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'orderController' method
com.shop.web.OrderController#list()
to {GET [/api/orders]}: There is already 'legacyOrderController' bean method
com.shop.legacy.LegacyOrderController#findAll() mapped.

Notice that it tells us everything we need: the bean name and method being registered, orderController and OrderController#list, the mapping in conflict, GET /api/orders, and the bean and method that already own it, legacyOrderController and LegacyOrderController#findAll. We do not need to search the code base; we need to look at those two methods.

2When Spring Raises It

RequestMappingHandlerMapping keeps a registry from each RequestMappingInfo, the combination of patterns, HTTP methods, params, headers, consumes and produces, to one handler method. When it registers a new method whose RequestMappingInfo is equal to one already in the registry, it cannot know which one should handle requests, so it fails immediately.

Notice the word equal. Two mappings that differ in any condition are distinct and both register fine, even if a request could match both; such overlaps are resolved at request time by specificity. Only identical mappings are rejected at startup.

Step throughWhat happens at registration
  1. Scan controller beansfind @RequestMapping methods
  2. Build RequestMappingInfopath + method + params + headers + consumes + produces
  3. Equal info already registered?
    YesIllegalStateException: Ambiguous mapping, startup failsNoRegister the method
  4. Next methodrepeat for every handler method

4 steps in order. Play them, or step through them one at a time.

3Cause 1: A Copied Controller

The most common cause is a controller copied as a starting point for a new one, a version 2 controller or a legacy one kept for compatibility, that still has the original class-level @RequestMapping. In the message above, LegacyOrderController was probably copied from OrderController and both still map /api/orders.

The fix depends on intent. If the legacy controller should no longer serve the path, delete it or change its prefix, for example to /api/legacy/orders. If both versions must exist, give them different paths such as /api/v1/orders and /api/v2/orders, or one of the conditions in the next section.

4Cause 2: Two Beans of the Same Controller Class

The other classic cause is that the same class became two beans with different names. Component scanning picks up OrderController as orderController, and a configuration class also declares it with a @Bean method, or a shared library jar contains a controller that is scanned by two applications' base packages under different names. Each bean registers the same methods, so the second registration collides with the first.

Java
@RestController
@RequestMapping("/api/orders")
class OrderController { ... } // bean 'orderController' from component scanning
@Configuration
class WebConfig {
@Bean OrderController ordersApi(OrderService s) { // second bean 'ordersApi' of the same class
return new OrderController(s);
}
}
// Ambiguous mapping. Cannot map 'ordersApi' method com.shop.web.OrderController#list()
// to {GET [/api/orders]}: There is already 'orderController' bean method com.shop.web.OrderController#list() mapped.

The giveaway is that both class names in the message are the same. The fix is to keep only one way of creating the bean. If the two beans had the same name, we would get a different startup error instead, about a bean definition that cannot be overridden, because Spring Boot disables bean overriding by default.

5Making Mappings Distinct on Purpose

Sometimes two methods should share a path but answer different requests. Then we add a condition that tells them apart. The conditions that count are the HTTP method, consumes, produces, params and headers.

Java
@GetMapping(path = "/api/orders", produces = "application/json")
List<OrderDto> list() { ... }
@GetMapping(path = "/api/orders", produces = "text/csv")
String export() { ... } // distinct: different produces
@GetMapping(path = "/api/orders", params = "status")
List<OrderDto> byStatus(@RequestParam String status) { ... } // distinct: requires ?status=
@GetMapping(path = "/api/orders", headers = "X-Api-Version=2")
List<OrderDtoV2> listV2() { ... } // distinct: requires the header
// all four register; requests are routed by Accept, query parameter or header

Notice that Java parameter names do not count as conditions, and patterns that differ only in a variable name, such as /{id} and /{login}, register fine but tie at request time. Distinct conditions avoid the startup error, but each must describe a real difference in the requests, or we just move the ambiguity to request time.

6Listing All Mappings

Once the application starts, the actuator's mappings endpoint lists every mapping with its handler. We expose it in a non-production profile and filter its JSON for the path we care about.

Java
management.endpoints.web.exposure.include=health,mappings
$ curl -s localhost:8080/actuator/mappings | jq -r '
.contexts[].mappings.dispatcherServlets[][]
| select(.predicate | contains("/api/orders")) | "\(.predicate) -> \(.handler)"'
{GET [/api/orders], produces [application/json]} -> com.shop.web.OrderController#list()
{GET [/api/orders], produces [text/csv]} -> com.shop.web.OrderController#export()

While the application is failing to start, the endpoint is not available, so the error message is the first tool. Turning on TRACE logging for org.springframework.web.servlet.mvc.method.annotation also prints the mappings detected for each controller during startup, which helps when we suspect a duplicate bean or an unexpected controller from a library; check your version for the exact logger output.

7Follow-up questions

How do you stop this from happening again?

A quick test that starts the web layer, such as a @WebMvcTest or a full @SpringBootTest in CI, fails on the same error before merge, so the conflict never reaches an environment. Keeping controller packages small and avoiding @Bean methods for controllers removes the duplicate-bean cause, and an ArchUnit rule can forbid classes in a legacy package from using the same class-level paths as the current API.

Why is this an error at startup but /users/{id} versus /users/{login} only at request time?

Because the startup check compares mappings for equality, and the two pattern strings differ, so both register. At request time both match /users/42 with equal specificity, and only then can Spring see the tie.

Can an interface with @RequestMapping cause it?

Yes. If two controller classes implement the same annotated interface, both inherit its mappings and collide.

8Conclusion

In this answer, we read the Ambiguous mapping error, which names both methods and the conflicting mapping, and saw that RequestMappingHandlerMapping rejects a method whose combination of path, HTTP method, params, headers, consumes and produces equals one already registered. The usual causes are a copied controller with the same paths and two beans of the same controller class. We fixed them by removing the duplicate or changing paths, made mappings deliberately distinct with conditions such as produces or params, and listed mappings with the actuator endpoint and startup logging.

What to say in the interviewAbout 90 seconds aloud

Open with

This error means two handler methods ended up with exactly the same mapping, meaning the same path, the same HTTP method and the same params, headers, consumes and produces conditions.

Then, if they want more

RequestMappingHandlerMapping keeps one handler per mapping, so when a second identical one is registered at startup, it refuses and the application fails to start. The message is very helpful: it names the bean and method being mapped, the mapping in conflict, like GET /api/orders, and the bean and method that already have it.

So I start by looking at those two methods. The usual cause is a copied controller, for example a legacy or version 2 controller that kept the original class-level path.

The other common one is two beans of the same controller class, say component scanning plus an @Bean method, or a shared library scanned twice; there the two class names in the message are identical. The fix is to remove the duplicate or give the controller a different path.

If both methods should really share a path, I make the mappings distinct with a real condition, such as different produces for JSON and CSV, a params condition, or a header for versioning. Once the app starts, the mappings actuator endpoint lists every mapping and its handler, which I filter with jq.

I would also make sure a web-layer test in CI starts the context, so this is caught before merge.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Startup fails with 'Ambiguous mapping. Cannot map method ... There is already ... bean...": https://scrivio-interview-library.netlify.app/spring-boot/mvc-architecture/786e4f2535/