在我的应用程序中,我公开了执行器端点。 一切正常,直到我尝试在应用程序以外的其他端口上公开执行器端点。 我正在尝试更改放入我的 application.yml 中的端口:
管理.服务器.端口=9001
如果我尝试使用另一个端口,则会出现错误:
com.finture.pp.dm.ewmservices.configuration.SpringFoxConfig 中方法 webEndpointServletHandlerMapping 的参数 4 需要一个类型为“org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties”的 bean,但无法找到。
行动:
考虑在配置中定义“org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties”类型的 bean。
使用 CorsEndpointProperties Bean 的类:
@Configuration
public class SpringFoxConfig {
@Bean
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(
WebEndpointsSupplier webEndpointsSupplier,
ServletEndpointsSupplier servletEndpointsSupplier,
ControllerEndpointsSupplier controllerEndpointsSupplier,
EndpointMediaTypes endpointMediaTypes,
CorsEndpointProperties corsProperties,
WebEndpointProperties webEndpointProperties,
Environment environment) {
//Do something
}
application.yml:
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
group:
readiness:
include: db, rabbit
show-details: ALWAYS
probes:
enabled: true
server:
port: 9001
知道如何解决这个问题吗? 在这种情况下,有没有办法在不同端口上公开执行器?
将以下注释添加到配置类解决了我的问题。 我的应用程序现在可以运行,但我无法通过 management.server.port 访问执行器。即使我设置了 management.server.port,执行器仍然在应用程序端口上运行。
@EnableConfigurationProperties({CorsEndpointProperties.class})
最后一堂课
@Configuration
@EnableConfigurationProperties({CorsEndpointProperties.class,
WebEndpointProperties.class})
public class SwaggerBaseConfiguration {
private final CorsEndpointProperties corsEndpointProperties;
private final WebEndpointProperties webEndpointProperties;
public SwaggerBaseConfiguration(CorsEndpointProperties corsEndpointProperties, WebEndpointProperties webEndpointProperties) {
this.corsEndpointProperties = corsEndpointProperties;
this.webEndpointProperties = webEndpointProperties;
}
// some beans
}
如果我能解决management.server.port问题,我将编辑这个答案。