首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改dispatcherServlet url映射后找不到Spring执行器端点

更改dispatcherServlet url映射后找不到Spring执行器端点
EN

Stack Overflow用户
提问于 2014-09-11 18:21:59
回答 1查看 2.1K关注 0票数 4

我用Spring Boot和Spring Actuator开发了我的第一个rest服务。我需要将servlet映射更改为不同的映射。因此,我的代码在@Configuration类中如下所示:

代码语言:javascript
复制
@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中排除了它的基本安全性:

代码语言:javascript
复制
security.ignored = **/directdebit/**

问题是我无法到达执行器端点。当我尝试localhost:8080/api/info时,我得到一个404 Not Found错误代码,并且我得到一个包含以下数据的审计事件:

代码语言:javascript
复制
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恢复到类路径中,并且从堆栈跟踪中可以看到没有找到映射:

代码语言:javascript
复制
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上下文路径?

EN

回答 1

Stack Overflow用户

发布于 2014-09-11 19:11:03

执行器端点的映射方式与DispatcherServlet不同。您可以使用应用程序属性management.contextPath更改执行器端点的路径,该属性默认情况下为'/‘。例如,您应该能够使用localhost:8080/info访问您的端点。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25784952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档