[英]Spring Boot 2 Actuator endpoints inaccessible with Jersey
I have a very simple demo application using the Spring Boot 2.0.x.RELEASE 我有一个使用Spring Boot 2.0.x.RELEASE的非常简单的演示应用程序
In my POM I have: 在我的POM中,我有:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<exclusions>
<exclusion>
<!-- We're using undertow as our embedded web container instead of tomcat -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Embedded web container- serves Jersey resources -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<!-- Support for Spring Actuator & Health Check Endpoints -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
My main application just looks like: 我的主要应用程序看起来像:
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
ResourceConfig getJerseyConfig() {
final HashMap<String, Object> jerseyProperties = new HashMap<>();
jerseyProperties.put(ServerProperties.MEDIA_TYPE_MAPPINGS, "json : application/json");
ResourceConfig resourceConfig = new ResourceConfig()
.register(TestEndpoints.class);
resourceConfig = resourceConfig.setProperties(jerseyProperties);
return resourceConfig;
}
}
When I then try and hit an actuator endpoint such as /actuator
I receive a 404, but I can hit the endpoints in TestEndpoints.java
with no problem. 当我尝试击中执行器端点(如
/actuator
我收到404,但我可以在TestEndpoints.java
点击端点没有问题。 I had this working with Spring Boot 1.5.x, but now it seems that Jersey is not allowing the actuator endpoints through. 我有这个使用Spring Boot 1.5.x,但现在看来Jersey不允许执行器端点通过。 If I remove the ResourceConfig bean completely, then I can hit the actuator endpoints.
如果我完全删除ResourceConfig bean,那么我可以点击执行器端点。 Is there some configuration I have to add to allow the actuator endpoints through jersey?
是否有一些配置我必须添加以允许执行器端点通过泽西?
It's because by default Jersey will use the url mapping /*
, which will hog up all requests, including those to the actuator endpoints, which it will not find. 这是因为默认情况下,泽西岛将使用url mapping
/*
,这将占用所有请求,包括那些它将找不到的执行器端点。 There are two solutions; 有两种解决方案; you can either change the base URL for Jersey to something else, eg
/api/*
or you can configure Jersey as a filter (instead of the default servlet) and set a property to make Jersey forward all requests it doesn't know down to the servlet container. 您可以将Jersey的基本URL更改为其他内容,例如
/api/*
或者您可以将Jersey配置为过滤器(而不是默认的servlet)并设置一个属性以使Jersey将所有不知道的请求转发到servlet容器。 Both examples can be found in this post . 这两个例子都可以在这篇文章中找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.