我有一个带有spring 1.4.2和CXF的项目设置。我想增加弹簧启动执行器的项目。这是我添加到项目中的配置。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
然后创建一个WAR文件,然后将其部署到外部tomcat服务器中。但是,当我访问健康网址localhost:8080/management/health时,它提供了404HTTP代码。服务器正常启动,我可以看到包含以下详细信息的日志:
健康配置日志
localhost-startStop-1 INFO org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping -映射到公共java.lang.Object上的“{/管理层/健康/管理/管理/健康.json,produces=application/json}”
Servlet配置日志
localhost-startStop-1 INFO org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean -映射过滤器:“springSecurityFilterChain”到: /* INFO org.springframework.boot.web.servlet.FilterRegistrationBean -映射筛选器:“webRequestLoggingFilter”到: /* INFO org.springframework.boot.web.servlet.FilterRegistrationBean -映射过滤器:“applicationContextIdFilter”到: /* INFO org.springframework.boot.web.servlet.ServletRegistrationBean -映射servlet:'dispatcherServletRegistration‘to INFO org.springframework.boot.web.servlet映射servlet:‘org.springframework.boot.web.servlet.ServletRegistrationBean’到/ INFO .ServletRegistrationBean -映射servlet:'CXFServlet‘到/services/*
发布于 2017-08-01 10:52:33
问题已经解决,细节如下。由于CXF和spring一起引导在一起,CXF和致动器端点都为'/'配置。为CXF RESt端点配置的servlet的名称是RESt由于CXF的启动程序在POM中,所以CXf的自动配置也在进行。因此,您可以发现CXFServlet也配置为/services/*。
映射servlet:'dispatcherServletRegistration‘到[] 映射servlet:“dispatcherServlet”到/ 映射servlet:“CXFServlet”到/services/*
我删除了自动配置选项(CXFServlet),因为我有一些CXF实现所需的定制,并将dispatcherServletRegistration映射到/services/*,现在一切正常。现在执行器工作在'/'和/services下的CXF REST API中。
发布于 2022-06-24 22:21:35
在我的例子中,我有Spring1.5.X,我不能为CXF和Spring使用两个不同的基本路径。我需要为根应用程序路径保留"/“,并为返回执行器健康结果添加一个RestEnpoint。
所以我使用另一种方法,当CXF返回在服务层上生成的Health中的一个字符串结果时,使用@Au牛毛+ ObjectMapper。
注意:您应该启用注释上下文支持来应用此解决方案。
以下解决办法适用于我:
将CXF Servlet保持在"/“上
在我的例子中,我使用Camel + CXF,但是您所需要做的就是为构建Health对象创建以下组件:
@Component
public class InfoHealthEndpoint extends HealthEndpoint {
@Autowired
private InfoEndpoint infoEndpoint;
public InfoHealthEndpoint(HealthAggregator healthAggregator, Map<String, HealthIndicator> healthIndicators) {
super(healthAggregator, healthIndicators);
}
@Override
public Health invoke() {
Health health = super.invoke();
return new Health.Builder(health.getStatus(), health.getDetails())
.withDetail("info", infoEndpoint.invoke())
.build();
}
}
并创建一个服务,返回CXF响应控制器的字符串结果。
@Service公共类HealthService {
@Autowired
private InfoHealthEndpoint infoHealthEndpoint;
@Autowired
private ObjectMapper mapper;
private static final String HEALTH_UP = "UP";
public void health(Exchange exchange) throws JsonProcessingException {
Health health = infoHealthEndpoint.invoke();
String healthReponse = mapper.writeValueAsString(infoHealthEndpoint.invoke());
if(!HEALTH_UP.equals(health.getStatus().getCode())){
Response response = Response.status(503).entity(healthReponse).build();
exchange.getOut().setBody(response);
exchange.setProperty(Exchange.ROUTE_STOP, Boolean.TRUE);
}else{
exchange.getIn().setBody(healthReponse);
}
}
}
注意:在我的例子中,im使用Apache (Exchange)作为路由上的set响应,但是这个解决方案可以通过使用简单的字符串返回来适用于另一种情况。
这个答案上@丹尼的学分:Combine Spring Boot Actuator /health and /info into one
https://stackoverflow.com/questions/45421261
复制相似问题