2
votes

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?

2
check the web.xml or spring-config.xml files to see if there is a default controller being specified or if the named controller (in your case FooController is being named or mapped to a specific URL/URI - blurfus

2 Answers

0
votes

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.

0
votes

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.