我用Spring Boot和Spring Actuator开发了我的第一个rest服务。我需要将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/**问题是我无法到达执行器端点。当我尝试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上下文路径不是'/‘,看起来管理端点就会中断。因此,问题是如何让执行器管理端点知道servlet上下文路径?
发布于 2014-09-11 19:11:03
执行器端点的映射方式与DispatcherServlet不同。您可以使用应用程序属性management.contextPath更改执行器端点的路径,该属性默认情况下为'/‘。例如,您应该能够使用localhost:8080/info访问您的端点。
https://stackoverflow.com/questions/25784952
复制相似问题