![](/img/trans.png)
[英]Jersey v1 Spring Boot change jersey root Path to expose actuator endpoints
[英]Spring Boot 2 Actuator endpoints inaccessible with Jersey
我有一个使用Spring Boot 2.0.x.RELEASE的非常简单的演示应用程序
在我的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>
我的主要应用程序看起来像:
@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;
}
}
当我尝试击中执行器端点(如/actuator
我收到404,但我可以在TestEndpoints.java
点击端点没有问题。 我有这个使用Spring Boot 1.5.x,但现在看来Jersey不允许执行器端点通过。 如果我完全删除ResourceConfig bean,那么我可以点击执行器端点。 是否有一些配置我必须添加以允许执行器端点通过泽西?
这是因为默认情况下,泽西岛将使用url mapping /*
,这将占用所有请求,包括那些它将找不到的执行器端点。 有两种解决方案; 您可以将Jersey的基本URL更改为其他内容,例如/api/*
或者您可以将Jersey配置为过滤器(而不是默认的servlet)并设置一个属性以使Jersey将所有不知道的请求转发到servlet容器。 这两个例子都可以在这篇文章中找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.