按照此处的说明操作:
http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
我将这些依赖项添加到我的项目中:
compile "io.springfox:springfox-swagger2:2.7.0"
compile "io.springfox:springfox-swagger-ui:2.7.0"
Run Code Online (Sandbox Code Playgroud)
并像这样配置 SpringFox Swagger:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
但是 Swagger UI 似乎没有启用。我试过:
我得到的只是:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Sep 11 09:43:46 BST 2017
There was an …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用SpringFox。
Spring Boot 版本:'org.springframework.boot:3.0.0-SNAPSHOT'
构建.gradle
dependencies {
...
implementation 'io.springfox:springfox-petstore:2.10.5'
implementation "io.springfox:springfox-swagger2:3.0.0"
implementation "io.springfox:springfox-oas:3.0.0"
implementation 'io.springfox:springfox-swagger-ui:3.0.0'
...
}
Run Code Online (Sandbox Code Playgroud)
Spring引导类
@SpringBootApplication
@EnableSwagger2
@EnableOpenApi
public class ServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
SwaggerUiWebMvc配置器
@Component
public class SwaggerUiWebMvcConfigurer implements WebMvcConfigurer {
private final String baseUrl;
public SwaggerUiWebMvcConfigurer(
@Value("${springfox.documentation.swagger-ui.base-url:}") String baseUrl) {
this.baseUrl = baseUrl;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String baseUrl = StringUtils.trimTrailingCharacter(this.baseUrl, '/');
registry.
addResourceHandler(baseUrl + "/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
.resourceChain(false);
}
@Override
public void addViewControllers(ViewControllerRegistry …Run Code Online (Sandbox Code Playgroud) 为了在 SpringBoot 2.7 中启用 Swagger,选择 springdoc-openapi 相对于 Springfox 的优点/缺点是什么
我正在运行一个服务,可以在以下位置访问Swagger UI:
http://serviceURL/swagger-ui.html
Run Code Online (Sandbox Code Playgroud)
但是,它位于代理之后,例如:
http://proxyURL/serviceName
Run Code Online (Sandbox Code Playgroud)
Swagger UI生成的URL看起来像:
http://proxyURL/
Run Code Online (Sandbox Code Playgroud)
而不是具有serviceName作为后缀的实际URL.据我所知,这意味着操纵basePath属性.根据文件:
swagger API文档无法再描述不同基本路径上的操作.在1.2及更早版本中,每个资源都可以有一个单独的basePath.在2.0中,为整个规范定义了basePath等价物(scheme + host + basePath).
@Api(basePath)已弃用,它没有说明使用什么以及如何使用它.如何使Swagger生成的路径正确显示?
我正在使用Spring Boot,Springfox Swagger和注释.
几天前,应用程序正在使用 Springfox Swagger 3.0。突然它停止工作。一周前创建的 Jar 文件仍在工作,但现在当我们尝试构建一个新的 Jar 文件时,即使没有任何代码/库更改,它也无法工作。我什至参考了以下 URL,但仍然面临问题。
swagger-ui 和 spring webflux 的 404 错误
下面给出了我的配置:
POM文件:
<properties>
<java.version>1.8</java.version>
<springfox.version>3.0.0-SNAPSHOT</springfox.version>
<spring.version>2.3.1.RELEASE</spring.version>
</properties>
<repositories>
<repository>
<id>spring-libs-milestone</id>
<name>Spring Milestone Maven Repository</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.version}</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
配置文件:
@Configuration
@EnableSwagger2WebFlux
public class SwaggerConfiguration implements WebFluxConfigurer {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.description("My Reactive API")
.title("My Domain object API") …Run Code Online (Sandbox Code Playgroud) 过去两年,我使用 Springfox 开发 Spring Boot 应用程序。Springfox 为您的 REST API 生成文档和测试用户界面。这太棒了。
但实际上 Springfox 项目已经死了并且不支持最新的 Spring。我有三个问题
更新 经过数月的大量使用和测试
SpringDoc OpenApi
我们的经历很好。
我有一个Spring Boot MVC java Web应用程序.我已经能够集成Springfox for API文档.当服务器启动并运行时,我可以直观地看到所有API.
如何生成OFFLINE swagger API文档?注意:我不想使用asciidoc或markdown文档,但我想在html文件中使用相同的swagger API用户界面.我想这样链接是相对于本地目录而不是本地主机服务器链接.谢谢
我有一个拥有不同消费者的api.我希望他们根据他们在春季安全中的角色获取相关文档.
例如
Api操作A受限于角色A和角色B.
Api操作B受限于角色B.
Api操作C对所有人开放
我正在使用springfox,spring 4,spring rest,security
我知道有一个名为@ApiIgnore的注释,也许可以使用它.
这是可能吗?
我正在使用 spring cloud 将模块化应用程序迁移到微服务应用程序,当我完成将模块迁移到微服务并运行它时,出现了一个问题:
更正应用程序的类路径,使其包含 org.springframework.plugin.core.PluginRegistry 的单个兼容版本
这是错误:
试图调用不存在的方法。尝试是从以下位置进行的:
org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory.<init>(UnwrappingRepositoryInvokerFactory.java:57)
以下方法不存在:
org.springframework.plugin.core.PluginRegistry.of(Ljava/util/List;)Lorg/springframework/plugin/core/PluginRegistry;
该方法的类 org.springframework.plugin.core.PluginRegistry 可从以下位置获得:
jar:file:/~/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar!/org/springframework/plugin /core/PluginRegistry.class
它是从以下位置加载的:
文件:/~/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar
行动:
更正应用程序的类路径,使其包含 org.springframework.plugin.core.PluginRegistry 的单个兼容版本
这是我的 pom.xml :
<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>
<父>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- 从存储库中查找父级 -->
</父>
<groupId>org.sid</groupId>
<artifactId>SF-postpros</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SF-postpros</name>
<description>Spring Boot 演示项目</description>
<属性>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR4</spring-cloud.version>
</属性>
<依赖>
<依赖>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<排除>
<排除>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</排除>
</排除>
</依赖>
<依赖>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>运行时</scope>
</依赖>
<依赖>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</依赖>
<依赖>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</依赖>
<依赖>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId> … springfox ×10
swagger ×7
spring-boot ×6
swagger-ui ×6
spring ×3
java ×2
swagger-2.0 ×2
spring-mvc ×1
spring-rest ×1
springdoc ×1