MrCatfishKing
MrCatfishKing

Reputation: 21

Spring URL when both controller and method do not have @RequestMapping values

I'm being asked to take over a piece of code. Being that I am not an seasoned Spring developer, I have a question on what is the URI when both the controller and method does not specify a value for @RequestMapping.

For example, the code looks like this:

@Controller
public class FooController {

    @RequestMapping
    public String getThis(String input) {
        return "This";
    }
}

So what is the URL that I need to access the getThis method?

Upvotes: 2

Views: 763

Answers (2)

WaM
WaM

Reputation: 1

Your method will not be reachable and you can see this via a warning message from Spring like :

21:57:50.608 [main] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor': no URL paths identified

If you need to have this method in the root URL, you need to use the value "/" instead of nothing.

Upvotes: 0

Dilip Kumar
Dilip Kumar

Reputation: 2534

Sometime back i also had the same doubt. Am thinking that Controller without @RequestMapping will throw an exception (am not sure).

For method case:

If you don't have any values in @RequestMapping, method will listen on Controller path and you dint specify any method so it will listen ALL HTTP Methods.

Upvotes: 0

Related Questions