Why am I getting a "requestMappingHandlerMapping" error when I have 2 controller methods which has same exact endpoint string value

Solution 1:

Yes and no. What you currently have is 2 get methods mapped to the same URL, there is no differentiator in the mapping for Spring to determine which one to use when a request comes in.

As you are using a request header in your second one, you could use the headers element on the @GetMapping to add an additional mapping info.

@GetMapping(path="/hello-world-internationalized", headers="Accept-Language")

Now if that specific header is present the method will now be called.

It is important that the mapping information (or metadata) needs to be unique for each method, if the information is the same you will get an error.

Solution 2:

You can't do that.

The integration of web framework and spring ioc in spring mvc is accomplished by monitoring the creation of servlet context through ContextLoaderListener and then loading the parent container. Then, by configuring a servlet object DispatcherServlet, the specific sub-container is loaded when DispatcherServlet is initialized.

So,overloading cannot be implemented with the same url。

You can implement overloading in Service.