当前位置: 首页 > 知识库问答 >
问题:

Spring Boot2执行器endpoint无法使用平纹针布

田兴怀
2023-03-14

我有一个使用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;
    }
}

然后,当我尝试并命中执行器endpoint(如/acture)时,我会收到一个404,但我可以命中testendpoints.java中的endpoint,没有任何问题。我在Spring Boot 1.5.x中使用了这个功能,但现在看来Jersey不允许执行器endpoint通过。如果我完全删除ResourceConfig bean,那么我就可以命中执行器endpoint。是否有一些配置我必须添加,以允许执行器endpoint通过泽西?

共有1个答案

申高峯
2023-03-14

这是因为默认情况下Jersey将使用url映射/*,这将占用所有请求,包括那些到执行器endpoint的请求,而它将找不到这些请求。有两种解决办法;您可以将Jersey的基本URL更改为其他URL,例如/api/*,也可以将Jersey配置为过滤器(而不是默认servlet),并设置一个属性,使Jersey将它不知道的所有请求转发到servlet容器。这两个例子都可以在这篇帖子中找到。

 类似资料:
  • 如何访问http://localhost:8081/Actuatorendpoint?

  • 我尝试在Spring启动中使用执行器endpoint。应用程序运行平稳。我的pom文件如下所示: 这是应用程序的内容。属性文件: 这是我的Spring Boot应用程序的开始: 每当我尝试通过键入连接/health、/Info或/metricsendpoint时http://localhost:8080/health,HTTP请求传输到http://localhost:8080/showMyLog

  • 详情: 我要访问的是“执行器”endpoint,而不是spring boot Acture(localhost:8080/acture)提供的其他endpoint 是,我已尝试在属性文件中手动启用该终结点(endpoints.enabled=true或endpoints.actuator.enabled=true) 是,我已尝试启用/禁用endpoint。敏感属性 是的,执行器的其他endpoin

  • 我正在尝试保护Spring Boot执行器endpoint。我的REST接口具有工作安全性,但尝试在内置endpoint上添加安全性似乎不起作用。 我在<code>应用程序中设置了endpoint分组。属性: 我的Java配置中有这个 当我使用浏览器转到<code>/api</code>以下的任何内容时,我得到了预期的403。例如,当转到/时,我看到返回的JSON也是403。 我还尝试将其添加到我

  • 从阅读Spring Boot参考文档可以看出,将Jersey资源注册为@Components似乎是一个要求。但事实似乎并非如此。在我看来,这似乎是Spring Boot参考文档中的一个小bug。文档可以从“Registered endpoints should be@components”更新为“Registered endpoints can be@components”。这有道理吗?