This is the same approach as john fuhr mentioned except more specific so you only log the URL mappings, not everything from the spring framework. I also use log4j.properties, instead of the .xml but you can convert it across if you like. I'm assuming you have an appender named mainAppender
defined too.
I'm using Spring 3.2.2.RELEASE but it may work with other versions too.
This logger is responsible for anything you mark with a @RequestMapping
:
log4j.logger.org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping=INFO, mainAppender
This is the logger responsible for <mvc:resources />
definitions:
log4j.logger.org.springframework.web.servlet.handler.SimpleUrlHandlerMapping=INFO, mainAppender
You may also want to add these two lines to stop duplicate output (printing the same line twice) if you experience that.
log4j.additivity.org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping=false
log4j.additivity.org.springframework.web.servlet.handler.SimpleUrlHandlerMapping=false
This is an example of the output I get:
14:29:43 INFO RequestMappingHandlerMapping.registerHandlerMethod():185 - Mapped "{[/splash],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String au.org.example.HomeController.splash(org.springframework.ui.Model)
14:29:43 INFO RequestMappingHandlerMapping.registerHandlerMethod():185 - Mapped "{[/home],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String au.org.example.HomeController.home(boolean,int,org.springframework.ui.Model)
14:29:44 INFO SimpleUrlHandlerMapping.registerHandler():302 - Root mapping to handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
14:29:44 INFO SimpleUrlHandlerMapping.registerHandler():315 - Mapped URL path [/js/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
14:29:44 INFO SimpleUrlHandlerMapping.registerHandler():315 - Mapped URL path [/images/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#1'
14:29:44 INFO SimpleUrlHandlerMapping.registerHandler():315 - Mapped URL path [/css/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#2'
It's not as pretty as what you're after but it does give you the first three columns of information (from your example table). You don't get the view names unfortunately.