Spring-boot: management.context-path does not override server.contextPath

Created on 7 Nov 2015  路  8Comments  路  Source: spring-projects/spring-boot

The management.context-path adds to any existing server.context-path instead of overriding it.

Prerequisites

  • Spring Boot 1.3.0.RC1
  • actuator enabled
  • application.properties configuration:
server.context-path=/v1
management.context-path=/manage

Expected result

  • The actuator resources should be present at localhost:8080/manage[actuator endpoint]

    Actual result

  • The actuator resources are located as subpath to /v1, i.e. localhost:8080/v1/manage/[actuator endpoint]

    Comments

  • Setting the management.port=8081 does not affect the root context of the actuator resources. In other words, they will be mapped to localhost:8081/v1/manage/[actuator resource]

  • Setting the management.context-path=/ (in attempt to re-enable the default management context path) still results the actuator resources to be mapped to localhost:8081/v1/[actuator resource]
bug

Most helpful comment

@snicoll Looks good from my point of view.

I have verified that:

  1. management.context-path will be appended to any existing server.context-path if the application and the actuator have the same port configuration.
  2. management.context-path will be the root context path if the application and the actuator have different port configurations.

Specifically:

  • server.context-path=/v1 results in :8080/v1/[application endpoint] and :8080/v1/[actuator endpoint]
  • server.context-path=/v1 and management.context-path=/manage results in :8080/v1/[application endpoint] and :8080/v1/manage/[actuator endpoint]
  • server.context-path=/v1 and management.port=8081 results in :8080/v1/[application endpoint] and :8081/[actuator endpoint]
  • server.context-path=/v1, management.port=8081 and management.context-path=/manage results in :8080/v1/[application endpoint] and :8081/manage/[actuator endpoint]

Thanks!

All 8 comments

I might have been a bit hasty labelling this as a bug. I think it's probably working as designed for all but the case where you're using a different port. When the port's the same, the actuator shares the main application's dispatcher servlet and, therefore, also shares its context path.

@wilkinsona I have just tested with the same port and with different port and The management.context-path adds to any existing server.context-path instead of overriding it in both cases.

We also just found out that the health checks on our microservices platform are not working anymore because of this issue. As a workaround we can change the actuator url but it would be nice if you can specify a different context path when you are using different server and management ports.

If the behavior's changed since 1.2.x then we need to reinstate the old behavior. If not, then we'll have to leave this as-is (for now at least).

There's a test in 7d04ca1 for the context-path behaviour in 1.2.x (confirming that there is a change in 1.3.0).

@matsev can you give that a try? (1.3.1.BUILD-SNAPSHOT coming up soon)

@snicoll Looks good from my point of view.

I have verified that:

  1. management.context-path will be appended to any existing server.context-path if the application and the actuator have the same port configuration.
  2. management.context-path will be the root context path if the application and the actuator have different port configurations.

Specifically:

  • server.context-path=/v1 results in :8080/v1/[application endpoint] and :8080/v1/[actuator endpoint]
  • server.context-path=/v1 and management.context-path=/manage results in :8080/v1/[application endpoint] and :8080/v1/manage/[actuator endpoint]
  • server.context-path=/v1 and management.port=8081 results in :8080/v1/[application endpoint] and :8081/[actuator endpoint]
  • server.context-path=/v1, management.port=8081 and management.context-path=/manage results in :8080/v1/[application endpoint] and :8081/manage/[actuator endpoint]

Thanks!

:+1:

Was this page helpful?
0 / 5 - 0 ratings