我使用Spring Boot和Spring Actuator开发了我的第一个休息服务。我需要将servlet映射更改为另一个。所以我的代码在@Configuration类中是以下代码:
@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;
}
服务端点工作正常,因为我在application.properties中排除了它的基本安全性:
security.ignored = **/directdebit/**
问题在于我无法到达Actuator端点。当我尝试localhost:8080 / api / info时,我得到一个404 Not Found错误代码,我得到一个包含以下数据的审计事件:
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}]
更新
从类路径中删除Spring Security后,我可以访问localhost:8080 / api / info。因此,问题与在类路径中找到Spring Security时应用于管理端点的安全性有关。
更新
还在为此而战。我已将String Security恢复到类路径,从堆栈跟踪中我可以看到找不到映射:
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
如果servlet上下文路径不是' /'看起来管理端点被破坏了。所以问题是如何让Actuator管理端点了解servlet上下文路径?。
答案 0 :(得分:1)
Actuator端点的映射方式与DispatcherServlet不同。您可以使用应用程序属性management.contextPath更改Actuator端点的路径,默认情况下为' /'。您应该能够使用localhost:8080 / info访问您的端点。