Spring Actuator 与 Springfox 冲突:“documentationPluginsBootstrapper”异常

问题描述 投票:0回答:3

我已将 Spring Boot 项目升级到 2.7.4,Springfox 升级到 3.0.0。 但这导致了异常,

无法启动bean“documentationPluginsBootstrapper”;嵌套异常是 java.lang.NullPointerException

经过一番研究,我在

application.properties
中添加了以下配置,但问题仍然没有解决。

spring.mvc.pathmatch.matching-strategy=ant-path-matcher

然后我发现,Spring Actuator导致了这个问题,并且设置以下属性解决了这个问题。

management.server.port=8082

我不想定义自定义管理端口,而是希望它采用默认服务器端口。

Actuator为何与Springfox冲突?我该如何解决这个问题?

pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.4</version>
        <relativePath />
</parent>

<properties>
        <java.version>1.8</java.version>
        <spring.cloud-version>2021.0.4</spring.cloud-version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-boot-starter</artifactId>
        <version>3.0.0</version>
    </dependency>
</dependencies>

Springfox Swagger 配置

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2).select()
                .apis(RequestHandlerSelectors.basePackage("com.swagger.io")).paths(PathSelectors.any()).build();
    }
}
java spring spring-boot swagger springfox
3个回答
1
投票

Springfox 已经有一段时间没有维护了。通过禁用最新的 Spring Boot 功能可以使其与 Spring Boot 2.7 一起使用,但可能不值得您花时间。它根本不可能与 Spring Boot 3 一起工作。

您可以使用 Springdoc 代替。迁移通常不需要太多工作:https://springdoc.org/migration-from-springfox.html


0
投票

通过在我的 bootstrap.properties 中使用以下属性,这也对我有用 管理.服务器.端口=0


0
投票

我也有同样的问题。尝试按照下面的文章进行操作。这个问题对我来说已经解决了。 https://medium.com/@amuralisundaram/harmonizing-swagger-3-x-and-spring-actuator-2-6-x-achieving-seamless-integration-42317c3ffaf7

© www.soinside.com 2019 - 2024. All rights reserved.