Spring Actuator endpoints not found after changing dispatcherServlet url mapping

I've developed my first rest service with Spring Boot and Spring Actuator. I needed to change the servlet mapping to a different one. So my code is the following in a @Configuration class:

@Bean
public DispatcherServlet dispatcherServlet() {
    return new DispatcherServlet();
}

@Bean
public ServletRegistrationBean dispatcherRegistration(final DispatcherServlet dispatcherServlet) {
    final ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet);
    registration.addUrlMappings("/api/*");
    return registration;
}

The service endpoint is working fine, as I've excluded basic security from it in application.properties:

security.ignored = **/directdebit/**

The problem is that I can't reach the Actuator endpoints. When I try localhost:8080/api/info I get a 404 Not Found error code and I get an audit event with the following data:

AuditEvent [timestamp=Thu Sep 11 12:12:29 CEST 2014, principal=anonymousUser, type=AUTHORIZATION_FAILURE, data={message=Access is denied, type=org.springframework.security.access.AccessDeniedException}]

UPDATE

After removing Spring Security from classpath, I can reach localhost:8080/api/info. So, the problem is related to the security applied to the management endpoints when Spring Security found in classpath.

UPDATE

Still fighting with this. I've restored String Security to the classpath and from stack trace I can see that the mappings are not found:

2014-09-16 11:01:09.011 DEBUG 780 --- [nio-8080-exec-2] o.s.s.web.util.matcher.OrRequestMatcher  : Trying to match using Ant [pattern='/mappings']
2014-09-16 11:01:09.011 DEBUG 780 --- [nio-8080-exec-2] o.s.s.w.u.matcher.AntPathRequestMatcher  : Checking match of request : '/api/mappings'; against '/mappings'
2014-09-16 11:01:09.011 DEBUG 780 --- [nio-8080-exec-2] o.s.s.web.util.matcher.OrRequestMatcher  : Trying to match using Ant [pattern='/mappings/']
2014-09-16 11:01:09.011 DEBUG 780 --- [nio-8080-exec-2] o.s.s.w.u.matcher.AntPathRequestMatcher  : Checking match of request : '/api/mappings'; against '/mappings/'
2014-09-16 11:01:09.011 DEBUG 780 --- [nio-8080-exec-2] o.s.s.web.util.matcher.OrRequestMatcher  : Trying to match using Ant [pattern='/mappings.*']
2014-09-16 11:01:09.012 DEBUG 780 --- [nio-8080-exec-2] o.s.s.w.u.matcher.AntPathRequestMatcher  : Checking match of request : '/api/mappings'; against '/mappings.*'
2014-09-16 11:01:09.012 DEBUG 780 --- [nio-8080-exec-2] o.s.s.web.util.matcher.OrRequestMatcher  : No matches found
2014-09-16 11:01:09.012 DEBUG 780 --- [nio-8080-exec-2] o.s.s.web.util.matcher.OrRequestMatcher  : Trying to match using Ant [pattern='/**']
2014-09-16 11:01:09.012 DEBUG 780 --- [nio-8080-exec-2] o.s.s.w.u.matcher.AntPathRequestMatcher  : Request '/api/mappings' matched by universal pattern '/**'
2014-09-16 11:01:09.012 DEBUG 780 --- [nio-8080-exec-2] o.s.s.web.util.matcher.OrRequestMatcher  : matched

It looks like the management endpoints are broken if the servlet context path is not '/'. So the question is how can I make Actuator management endpoints aware of the servlet context path?.

Upvotes: 4

Views: 2766

Answers (1)

dunni
dunni

Reputation: 44545

The Actuator endpoints are mapped differently from the DispatcherServlet. You can change the path of the Actuator endpoints with the application property management.contextPath, which is by default '/'. You should be able to access your endpoints with localhost:8080/info for example.

Upvotes: 1

Related Questions