Swagger 斯普林福斯+;WebFlux&x2B;JavaX验证(JSR303)支持
我正在尝试为文档实现Swagger,以便它同时选择JSR303验证注释和基于SpringWebFlux的类 在Spring Boot项目中,我目前正在使用:Swagger 斯普林福斯+;WebFlux&x2B;JavaX验证(JSR303)支持,swagger,spring-webflux,reactive,springfox,jsr,Swagger,Spring Webflux,Reactive,Springfox,Jsr,我正在尝试为文档实现Swagger,以便它同时选择JSR303验证注释和基于SpringWebFlux的类 在Spring Boot项目中,我目前正在使用: 针对某些类的SpringWebFlux框架 JSR303关于Bean验证和约束的域类的注释 与SpringFox框架的Swagger集成,用于生成OpenAPI文档 在build.gradle中,使用了以下依赖项,我能够使Spring Webflux+SpringFox工作,但只有JSR 303给出了问题: springBootVersio
springBootVersion = '2.0.2.RELEASE'
//JavaX-validation
'javax.validation:validation-api:2.0.0.Final',
'javax.el:javax.el-api:3.0.0',
'org.glassfish.web:javax.el:2.2.6'
//SpringFox-Swagger
'io.springfox:springfox-swagger2:2.9.2',
'io.springfox:springfox-spring-webflux:3.0.0-SNAPSHOT',
'io.github.swagger2markup:swagger2markup-gradle-plugin:1.3.3'
问题是: 当添加以下依赖项以实现“SpringWebFlux+SpringFox+JSR303”时 我得到以下错误
[WARN ] 2018-11-01 10:16:50.535 [main] SpringApplication - Unable to close ApplicationContext
java.lang.IllegalStateException: Failed to introspect Class
springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@764c12b6]
at
org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:659) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at
org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:556 ) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.ge tTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:724) ~[spring- beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at
org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:861) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at
org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:810) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
Caused by: java.lang.NoClassDefFoundError:
org/springframework/web/servlet/HandlerMapping
at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_92]
at java.lang.Class.privateGetDeclaredMethods(Unknown Source) ~[?:1.8.0_92]
at java.lang.Class.getDeclaredMethods(Unknown Source) ~[?:1.8.0_92]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:641) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
... 20 more
Caused by: java.lang.ClassNotFoundException: org.springframework.web.servlet.HandlerMapping
at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_92]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_92]
一些博客说,SpringBoot版本2x不支持JSR303。我不确定,但我试着看它是否起作用
请告知
另外,如果当前不支持JSR303,那么除了JSR303之外,还可以使用哪些其他验证注释?
我不想使用Swagger核心注释,只是因为它会弄乱代码的可读性。springfox官方不支持SpringWebFlux(更多信息可以在这里阅读:)。 但您可以尝试以下快照版本: 正如我看到的版本大于2.3.2,对bean验证注释的支持:。添加到pom.xml中:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
<scope>compile</compile>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>3.0.0</version>
</dependency>
在您大摇大摆的配置中。我很想使用快照,但它无法定位库。pom.xml给定错误
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
<scope>compile</compile>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>3.0.0</version>
</dependency>
@EnableSwagger2