2

I have created simple spring boot application using spring initilzr. POM is:

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

then I add simple controller which returns string 'hello'. Endpoint works and I am happy but I would like to have all registered mappings in log during starting application. How to achieve that?

user109447
  • 1,069
  • 1
  • 10
  • 20
  • At startup, Spring Boot will list all available mappings. Look for entries like "INFO 32375 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping" in your startup logs – sechanakira Feb 19 '19 at 13:18
  • Unfortunatelly, there is no RequestMappingHandlerMapping log lines – user109447 Feb 19 '19 at 13:37
  • Have you looked in this answer: https://stackoverflow.com/questions/43541080/how-to-get-all-endpoints-list-after-startup-spring-boot ? And also Spring doc for `mappings` here: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html – Antot Feb 19 '19 at 13:43
  • Possible duplicate of [How to Get All Endpoints List After Startup, Spring Boot](https://stackoverflow.com/questions/43541080/how-to-get-all-endpoints-list-after-startup-spring-boot) – Antot Feb 19 '19 at 13:43

1 Answers1

1

One way could be to use Spring Boot Actuator to monitor the application mappings.
You will then be able to monitor the data either with JMX or HTTP.

How to :

  1. Add Spring Boot Actuator (see https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-enabling)

Add this dependency :

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
  1. Expose the mappings (see https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-endpoints-exposing-endpoints)

2a. For HTTP :

Add this line to application.properties :

management.endpoints.web.exposure.include=info, health, mappings

Then check this endpoint : http://localhost:8080/actuator/mappings (JSON data)

2b. For JMX :

Add this line to application.properties :

spring.jmx.enabled=true

Then check the MBeans prefixed by org.springframework.boot, with VisualVM for example.

Guillaume Husta
  • 4,049
  • 33
  • 40