我正在尝试为我的 spring 应用程序配置 swagger。下面是配置。但是,得到一个错误
[springfox/documentation/spring/web/SpringfoxWebMvcConfiguration.class] 无法打开,因为它不存在
Spring 版本 - 4.0.4 Springfox 版本 - 2.9.2
它不是 Maven 项目,我将所有必需的 jar 文件添加到类路径中。
弹簧上下文.xml
<bean id="Swagger" class="skt.test.SwaggerConfig" />
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
Run Code Online (Sandbox Code Playgroud)
Swagger 配置类
package skt.test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
@EnableWebMvc
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)
包含 Jar 文件 https://i.imgur.com/sYaYnrY.png
org.springframework.beans.factory.BeanDefinitionStoreException: …Run Code Online (Sandbox Code Playgroud) 我迁移到最新springfox-swagger2版本,2.10.0但看起来@EnableSwagger2已被弃用。
为了在 Spring Boot 项目中启用 Swagger,我应该使用什么注释?@EnableSwagger2WebMvc?
我在使用 springfox-swagger2 v2.2.0 时遇到与 HTTP URL 的请求填充端口 80 相关的问题。
无论如何,是否可以基于 Spring Profile 以编程方式禁用端口的生成或将端口设置为 443?
生成的卷曲:
curl -X GET --header "Accept: application/json" " https://test.com:80/api/users/search "
有人在 Spring webflux 环境中使用 Swagger 库来描述 webservice 的解决方案吗?
目标是使用 Swagger 自动生成 ws 客户端存根。
我正在使用 springfox 版本 2.9.2 和 swagger 注释 1.5.x。ApiModel 注释支持使多态性工作所需的鉴别器、子类型和父属性,但我没有看到生成正确的 apidocs 以启用多态性。
这是我的注释代码。
@RestController
@RequestMapping("/api/vehicles")
public class VehicleController {
private static final Logger LOGGER = LoggerFactory.getLogger(VehicleController.class);
@PostMapping(consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE})
void post(@RequestBody Vehicle anyVehicle) {
LOGGER.info("Vehicle : {}", anyVehicle);
}
}
@ApiModel(discriminator = "type", subTypes = {Car.class, Bike.class})
public class Vehicle {
String brand;
String type;
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getType() {
return type;
}
public void setType(String …Run Code Online (Sandbox Code Playgroud) 我必须从 swagger 上传 MultipartFile 类型的多个文件来测试我的 api。邮递员确实允许上传,但是,同样的事情在 swagger 中不起作用。
多部分文件列表的代码:
@ApiParam(name = "file", value = "Select the file to Upload", required = true, allowMultiple=true)
@RequestPart(value = "file", required = true) List<MultipartFile> file
Run Code Online (Sandbox Code Playgroud)
用于多部分文件列表的工作 curl 命令:
curl -X POST "http://localhost:8080/test" -H "accept: */*" -H "Content-Type: multipart/form-data" -F "file=@example1.pdf;application/pdf;" -F "file=@example2.pdf;application/pdf;" -F "jsonString={}"
Run Code Online (Sandbox Code Playgroud)
单个多部分文件也可以像这样在 swagger 中工作:
@ApiParam(name = "file", value = "Select the file to Upload", required = true, allowMultiple=true)
@RequestPart(value = "file", required = true) MultipartFile file
Run Code Online (Sandbox Code Playgroud)
依赖:
<!-- swagger -->
<dependency> …Run Code Online (Sandbox Code Playgroud) 我的项目中的 Swagger 文档有多个组。每个组都有一个Docket端点(每个组的成员)都用自定义注释进行标记。例如,这里是Docket身份验证组:
@Bean
public Docket authenticationApis() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("authentication")
.useDefaultResponseMessages(false)
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(AuthenticationApiGroup.class))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
.securitySchemes(Collections.singletonList(securityScheme()))
.securityContexts(Collections.singletonList(securityContext()));
}
Run Code Online (Sandbox Code Playgroud)
Docket所有可用端点还有一个(默认) 。问题是,当我调用文档 URL 时,Swagger UI 默认加载最上面的组.../swagger-ui.html。就我而言,它是身份验证组,因为这些组是按字母顺序排序的。所需的行为是将默认组加载为默认 API 组。我怎样才能做到这一点?
我尝试用 来命名默认值Docket,因此.groupName("all")它是最顶层的组(all < authentication),但这个解决方案有点“脏”,在这种情况下,文档将有两个重复的组(all和default)。
Springfox 2.9.2项目中使用。
我正在使用 3.0.0 记录使用 Spring Boot 2.4.3 创建的 API springfox-swagger。所以我现在有以下页面。
我的客户想要将 Swagger UI 徽标更改为他们自己的。我做不到。我搜索并找到了一些解决方案,但它不起作用。
在 下添加了以下自定义代码/resource/static/swaggercustm.css。但没有任何变化。
.swagger-ui img {
content: url('/static/css/mylogo.png');
width: 140px;
height: 40px;
}
Run Code Online (Sandbox Code Playgroud)
导入swagger-ui.css到本地并尝试修改图像路径。但这也没有帮助。
有人可以帮我修改徽标吗?如何覆盖徽标属性?
使用 Spring Boot 2.4.5 和 IntelliJ 2021.2。迁移后
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
到
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.10</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
每次我访问http://localhost:8080/swagger-ui.html. 该页面说:
获取错误未定义/v3/api-docs
当我检查日志时:
java.lang.IllegalStateException:为“/v3/api-docs”映射的处理程序方法不明确:{public org.springframework.http.ResponseEntity springfox.documentation.oas.web.OpenApiControllerWebMvc.getDocumentation(java.lang.String,javax.servlet) .http.HttpServletRequest), public java.lang.String org.springdoc.webmvc.api.OpenApiWebMvcResource.openapiJson(javax.servlet.http.HttpServletRequest,java.lang.String) 抛出 com.fasterxml.jackson.core.JsonProcessingException} org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:426)在org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:377)在org.springframework.web.servlet。 mvc.method.RequestMappingInfoHandlerMapping.getHandlerInternal(RequestMappingInfoHandlerMapping.java:125)在org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getHandlerInternal(RequestMappingInfoHandlerMapping.java:67)在org.springframework.web.servlet.handler.AbstractHandlerMapping。 getHandler(AbstractHandlerMapping.java:498) 在 org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1257) 在 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039) 在 org.springframework .web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) 在 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) 在 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java :898)
似乎有一个重复的处理程序方法,与 SpringFox 具有相同的路径,我如何从 SpringFox 中删除该方法(它不再存在于我的 pom 文件中)?
我正在构建一个应用程序,我希望有两个 swagger url:
http://localhost:8080/order-swagger.ui.html
http://localhost:8080/inventory-swagger.ui.html
我读了很多文章但没有找到任何解决方案。我发现定义两个 doket bean 但它并不能有效地构建两个 html 页面。它在右上角的下拉列表中创建 2 个项目。
如果您能提供如何操作,我们将不胜感激。
springfox ×10
swagger ×7
swagger-ui ×5
spring ×4
spring-boot ×4
java ×2
swagger-2.0 ×2
rest ×1
springdoc ×1