请问这是缺少什么配置吗
marshalby2 opened this issue · 6 comments
Error creating bean with name 'createSpringFoxRestApi' defined in class path resource [com/spring4all/swagger/DocketConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [void]: Factory method 'createSpringFoxRestApi' threw exception; nested exception is java.lang.NullPointerException: Cannot invoke "java.util.List.stream()" because "properties" is null
报的错一模一样
@marshalby2 @wuyinq
有 Demo 工程或者其他么?我可以验证定位一下。
@marshalby2 @wuyinq 有 Demo 工程或者其他么?我可以验证定位一下。
工程就是简单的spring项目,然后pom.xml里面增加配置:
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
在application.yaml里面增加配置:
springfox:
documentation:
enabled: true
swagger:
base-package: 'com.example'
base-path: '/**'
title: '注解方式的Swagger'
description: '这是注解方式的Swagger'
version: '2.0.1.RELEASE'
license-url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
license: 'The Apache License'
contact:
name: '吕小白'
url: 'https:www.baidu.com'
email: '******@qq.com'
其他没有增加配置,在运行项目的时候就会报出这个错误;还有,在使用低一点的版本的时候使用和demo一样的配置也会报出不同的错误,但是也是启动不了项目,暂时还不清楚是哪里出了问题。
使用的java-16,编辑器是VScode,spring boot版本最新刚配置的
Error creating bean with name 'createSpringFoxRestApi' defined in class path resource [com/spring4all/swagger/DocketConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [void]: Factory method 'createSpringFoxRestApi' threw exception; nested exception is java.lang.NullPointerException: Cannot invoke "java.util.List.stream()" because "properties" is null
建议你查看一下spring boot 的版本,如果是2.6.0-M3,可以改成2.6.0-M2试一下
和我报的错一样,从2.0.1.RELEASE降低至1.9.1.RELEASE就正常了,环境是springboot 2.5.6,flowable 6.7.0
我看了下,确实是缺少了部分全局配置导致的,主要是:globalOperationParameters的全局配置
复现版本:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.spring4all/swagger-spring-boot-starter -->
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
配置文件
logging:
level:
root: debug
spring:
application:
name: swagger-demo-issue-221
springfox:
documentation:
enabled: true
swagger:
globalOperationParameters:
-
name: timestamp
description: access timestamp
modelRef: integer
parameterType: header
required: false
base-package: 'com.example'
base-path: '/**'
exclude-path: '/error, /ops/**'
title: '注解方式的Swagger'
description: '这是注解方式的Swagger'
version: '2.0.1.RELEASE'
license-url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
license: 'The Apache License'
contact:
name: '吕小白'
url: 'https:www.baidu.com'
email: '******@qq.com'
host: localhost:8080