Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a quick lookup for url-to-controller mapping when @RequestMapping is used?

Given a web app that completely uses @RequestMapping to tie urls to a controller, I was wondering if there is a way or plug-in that would produce the web app's complete url-to-controller mappings?

Similar to struts.xml where you have all the urls mapping to an action hence you can see these information in a central place?

Otherwise, what happens is given a url from the screen, I end up doing a java file search each time I want to lookup that url's controller.

like image 819
Carlos Jaime C. De Leon Avatar asked Aug 18 '11 08:08

Carlos Jaime C. De Leon


2 Answers

Eclipse has plugin Springsource Tool Suite (you can also download it standalone): http://www.springsource.com/developer/sts You must first add Spring project nature to your project, then switch to Java EE perspective and then you will see "Spring Elements" in your project and there you will see all request mappings (and much more).

edit: useful features like this in STS made me switch from NetBeans to Eclipse.

like image 58
jirka.pinkas Avatar answered Oct 23 '22 09:10

jirka.pinkas


You can always wire the DefaultAnnotationHandlerMapping and extract all mappings. Something like:

@Autowired
// org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
private DefaultAnnotationHandlerMapping defaultAnnotationHandlerMapping;

public void outputMappings() {
for (Map.Entry<String, Object> entry : 
    defaultAnnotationHandlerMapping.getHandlerMap().entrySet()) {
        System.out.println(entry.getKey() + "->" + 
                           entry.getValue().getClass().getName());
    }

}

See AbstractUrlHandlerMapping.getHandlerMap() and DefaultAnnotationHandlerMapping

like image 38
pap Avatar answered Oct 23 '22 11:10

pap