SpringBoot 2.2.4执行器-自定义管理端点的路径



从spring boot v1.3升级到最新的spring boot v2.2.4后,我们失去了在管理端口下拥有自定义端点的能力。

在我们将自定义端点声明为:之前

@Component
public class CacheEndpoint implements MvcEndpoint {
...
@Override
public String getPath() {
return "/v1/cache";
}
...
// mappings goes here

由于MvcEndpoint已经从弹簧靴执行器中移除,现在我们需要做下一步:

@Component
@RestControllerEndpoint(id = "cache")
public class CacheEndpoint {
...
// mappings goes here

不幸的是,我们失去了为我们的自定义管理端点(在/v1/之前(提供自定义根路径的选项

为了向后兼容性,我们仍然希望有默认的执行器端点,如healthmetricsenv。。处于CCD_ 6基本路径下。例如host:<management_port>/health,但同时我们仍然希望在/v1/路径下支持我们的自定义端点,例如host:<management_port>/v1/cache

我尝试了很多东西,googled甚至更多,但还没有成功。有办法做到这一点吗?

这是我在spring-boot2:中使用的

application.yml:


management:
endpoints:
enabled-by-default: true
web:
exposure:
include: "*"
base-path: "/management" # <-- note, here is the context path

总而言之,考虑阅读致动器从弹簧套1.x到2.x 的迁移指南

最新更新