Java Spring启动验证信息未显示在Swagger UI中

Java Spring启动验证信息未显示在Swagger UI中,java,spring-boot,swagger,swagger-2.0,springfox,Java,Spring Boot,Swagger,Swagger 2.0,Springfox,我的类是用SpringBootJava编写的,我使用Swagger 2生成它们的文档。 我使用的是SpringFox版本2.9.0 为了在Swagger UI中显示验证约束(@min、@max、@pattern等),我在application.java中添加了以下几行,其中showExtensions(true),但这不起作用。 我应该改变什么来获得想要的结果 @Bean UiConfiguration uiConfig() { return UiConfigurationBuilder.

我的类是用SpringBootJava编写的,我使用Swagger 2生成它们的文档。 我使用的是SpringFox版本2.9.0

为了在Swagger UI中显示验证约束(@min、@max、@pattern等),我在application.java中添加了以下几行,其中showExtensions(true),但这不起作用。

我应该改变什么来获得想要的结果

@Bean
UiConfiguration uiConfig() {
  return UiConfigurationBuilder.builder() 
      .deepLinking(true)
      .displayOperationId(false)
      .defaultModelsExpandDepth(1)
      .defaultModelExpandDepth(1)
      .defaultModelRendering(ModelRendering.EXAMPLE)
      .displayRequestDuration(false)
      .docExpansion(DocExpansion.NONE)
      .filter(false)
      .maxDisplayedTags(null)
      .operationsSorter(OperationsSorter.ALPHA)
      .showExtensions(true)
      .tagsSorter(TagsSorter.ALPHA)
      .supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS)
      .validatorUrl(null)
      .build();
}

您的
ui配置
很好。您需要做的是(激活对JSR-303的Springfox支持):

  • springfoxbean验证程序
    依赖项添加到您的
    pom.xml

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-bean-validators</artifactId>
        <version>2.9.2</version> <!-- or any version you like -->
    </dependency>
    
现在,您应该能够在Swagger UI中的注释属性顶部看到所需的信息

...
@Import({springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration.class})
public class SwaggerDocumentationConfig { ... }