gpt4 book ai didi

更改 dispatcherServlet url 映射后找不到 Spring Actuator 端点

转载 作者:行者123 更新时间:2023-12-02 03:32:31 25 4
gpt4 key购买 nike

我已经使用 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/**

问题是我无法到达执行器端点。当我尝试 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 上下文路径?

最佳答案

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

关于更改 dispatcherServlet url 映射后找不到 Spring Actuator 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25784952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com