I've a Spring application that expose restful endpoints through @RequestMapping annotation in Controller classes.
I wish that were logged into the console, at server startup, all the endpoints of all the application's controller.
I use a tomcat server and log4j for logging.
Thanks.
In log4J, add the info log level for
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
class.With the level
INFO
:You should have this kind of information (lines are truncated):
UPDATE
Since Spring MVC 5.1, the logging strategy has changed.
Now very few information are logged with the
INFO
level, theDEBUG
level provides more information but it is not detailed.Only the
TRACE
level will provide detail information.Here is the changelog (emphasis is mine) :
So change the logging configuration in this way to list all mappings :
Log4J properties way :
Logback way :
For those who use spring-boot:
In the latest spring-boot release (since v2.1), they changed the mapping default log level (as specified in the Release Notes here).
Add one of the following properties to application.properties file:
logging.level.web=TRACE
logging.level.org.springframework.web=TRACE
Sample Console Output:
To add to the previous answer in
Spring Boot
there is the Actuator that among other things is exposing a dedicated Endpoint calledmappings
accessible under/mappings
.