网上找了好多springboot2.6.x+swagger3的配置,基本都没大问题。加上magic-api之后,要么启动报documentationPluginsBootstrapper相关错误,要么应用响应404。
在erupt+magic-api的环境下,其实不需要在启动类上配置@EnableSwagger2或者@EnableOpenApi,以下为关键依赖:
<dependency>
<groupId>xyz.erupt</groupId>
<artifactId>erupt-magic-api</artifactId>
<version>${erupt.version}</version>
</dependency>
<dependency>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-plugin-swagger</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version> <!--springboot2.6以上版本只能使用swagger3-->
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-ui</artifactId>
<version>3.0.2</version>
</dependency>
启动类上标注以下注解即可:
@SpringBootApplication
@EntityScan
@EruptScan