How will you make two ambiguity URL working in spring boot without changing the HTTP method type and no change will be accepted in URL as well?

Two controller methods that share the same URL and HTTP method can coexist without a mapping conflict by distinguishing them with request parameters or headers, so Spring routes based on which parameter is present.

Key Points: • Adding params to @GetMapping (e.g. params = "type=admin") makes Spring match the request only when that parameter is present with that value. • This avoids changing the URL path or switching to a different HTTP verb. • Without a distinguishing params/headers condition, Spring Boot throws an AmbiguousMappingException at startup. • The same technique works with headers = "..." if you'd rather disambiguate by a header instead of a query parameter. • This pattern is useful for versioning or variant behavior on a single logical endpoint without polluting the URL structure.

Example: GET /users?type=admin can route to a different handler than GET /users?type=customer, even though both share the same base path and HTTP method, because Spring matches on the params condition.

Code Example:

@GetMapping(value = "/users", params = "type=admin")
public List<UserDto> getAdmins() { ... }

@GetMapping(value = "/users", params = "type=customer")
public List<UserDto> getCustomers() { ... }

Interview Tip: A concise interview answer is:

"I'd keep the URL and HTTP method identical but add a params condition to each @GetMapping, like params = \"type=admin\" versus params = \"type=customer\". Spring then disambiguates the mapping based on which query parameter is present, without needing to touch the URL or verb."