(1)错误信息
在搭建SpringBoot整合swagger项目时候,启动项目,报错:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.0.RELEASE)
2021-07-19 20:07:55.902 INFO 19296 --- [ main] c.g.zhuyb.swagger.SwaggerApplication : Starting SwaggerApplication on zhuyb with PID 19296 (H:\03--java_workspace\java_study_space\sp_swagger\springboot_swagger\target\classes started by zhuyb in H:\03--java_workspace\java_study_space\sp_swagger\springboot_swagger)
2021-07-19 20:07:55.904 INFO 19296 --- [ main] c.g.zhuyb.swagger.SwaggerApplication : No active profile set, falling back to default profiles: default
2021-07-19 20:07:57.243 INFO 19296 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-07-19 20:07:57.253 INFO 19296 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-07-19 20:07:57.253 INFO 19296 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.35]
2021-07-19 20:07:57.332 INFO 19296 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-07-19 20:07:57.332 INFO 19296 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1390 ms
2021-07-19 20:07:57.646 INFO 19296 --- [ main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2Controller#getDocumentation(String, HttpServletRequest)]
2021-07-19 20:07:57.724 INFO 19296 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-07-19 20:07:57.837 INFO 19296 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-07-19 20:07:57.837 INFO 19296 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2021-07-19 20:07:57.863 INFO 19296 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2021-07-19 20:07:57.888 INFO 19296 --- [ main] s.d.s.w.s.ApiListingReferenceScanner : Scanning for api listing references
2021-07-19 20:07:57.969 WARN 19296 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is com.google.common.util.concurrent.ExecutionError: com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: javax/validation/constraints/Min
2021-07-19 20:07:57.969 INFO 19296 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2021-07-19 20:07:58.318 INFO 19296 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-07-19 20:07:58.336 INFO 19296 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-19 20:07:58.336 ERROR 19296 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is com.google.common.util.concurrent.ExecutionError: com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: javax/validation/constraints/Min
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:894) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
at com.gitee.zhuyb.swagger.SwaggerApplication.main(SwaggerApplication.java:16) [classes/:na]
Caused by: com.google.common.util.concurrent.ExecutionError: com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: javax/validation/constraints/Min
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2212) ~[guava-20.0.jar:na]
at com.google.common.cache.LocalCache.get(LocalCache.java:4053) ~[guava-20.0.jar:na]
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4057) ~[guava-20.0.jar:na]
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4986) ~[guava-20.0.jar:na]
at springfox.documentation.schema.CachingModelProvider.modelFor(CachingModelProvider.java:59) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.spring.web.scanners.ApiModelReader.read(ApiModelReader.java:69) ~[springfox-spring-web-2.9.2.jar:null]
at springfox.documentation.spring.web.scanners.ApiListingScanner.scan(ApiListingScanner.java:133) ~[springfox-spring-web-2.9.2.jar:null]
at springfox.documentation.spring.web.scanners.ApiDocumentationScanner.scan(ApiDocumentationScanner.java:71) ~[springfox-spring-web-2.9.2.jar:null]
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.scanDocumentation(DocumentationPluginsBootstrapper.java:101) ~[springfox-spring-web-2.9.2.jar:null]
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.start(DocumentationPluginsBootstrapper.java:167) ~[springfox-spring-web-2.9.2.jar:null]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
... 14 common frames omitted
Caused by: com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: javax/validation/constraints/Min
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2212) ~[guava-20.0.jar:na]
at com.google.common.cache.LocalCache.get(LocalCache.java:4053) ~[guava-20.0.jar:na]
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4057) ~[guava-20.0.jar:na]
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4986) ~[guava-20.0.jar:na]
at springfox.documentation.schema.property.CachingModelPropertiesProvider.propertiesFor(CachingModelPropertiesProvider.java:64) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.DefaultModelProvider.properties(DefaultModelProvider.java:166) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.DefaultModelProvider.reflectionBasedModel(DefaultModelProvider.java:100) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.DefaultModelProvider.modelFor(DefaultModelProvider.java:95) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.CachingModelProvider$1.load(CachingModelProvider.java:51) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.CachingModelProvider$1.load(CachingModelProvider.java:49) ~[springfox-schema-2.9.2.jar:null]
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3628) ~[guava-20.0.jar:na]
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2336) ~[guava-20.0.jar:na]
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2295) ~[guava-20.0.jar:na]
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2208) ~[guava-20.0.jar:na]
... 24 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/validation/constraints/Min
at springfox.bean.validators.plugins.schema.MinMaxAnnotationPlugin.extractMin(MinMaxAnnotationPlugin.java:57) ~[springfox-bean-validators-2.9.2.jar:null]
at springfox.bean.validators.plugins.schema.MinMaxAnnotationPlugin.apply(MinMaxAnnotationPlugin.java:48) ~[springfox-bean-validators-2.9.2.jar:null]
at springfox.documentation.schema.plugins.SchemaPluginsManager.property(SchemaPluginsManager.java:63) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.property.OptimizedModelPropertiesProvider.beanModelProperty(OptimizedModelPropertiesProvider.java:326) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.property.OptimizedModelPropertiesProvider.access$200(OptimizedModelPropertiesProvider.java:76) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.property.OptimizedModelPropertiesProvider$2.apply(OptimizedModelPropertiesProvider.java:175) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.property.OptimizedModelPropertiesProvider$2.apply(OptimizedModelPropertiesProvider.java:161) ~[springfox-schema-2.9.2.jar:null]
at com.google.common.base.Present.transform(Present.java:75) ~[guava-20.0.jar:na]
at springfox.documentation.schema.property.OptimizedModelPropertiesProvider.candidateProperties(OptimizedModelPropertiesProvider.java:218) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.property.OptimizedModelPropertiesProvider.propertiesFor(OptimizedModelPropertiesProvider.java:132) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.property.OptimizedModelPropertiesProvider.propertiesFor(OptimizedModelPropertiesProvider.java:118) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.property.CachingModelPropertiesProvider$1.load(CachingModelPropertiesProvider.java:56) ~[springfox-schema-2.9.2.jar:null]
at springfox.documentation.schema.property.CachingModelPropertiesProvider$1.load(CachingModelPropertiesProvider.java:54) ~[springfox-schema-2.9.2.jar:null]
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3628) ~[guava-20.0.jar:na]
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2336) ~[guava-20.0.jar:na]
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2295) ~[guava-20.0.jar:na]
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2208) ~[guava-20.0.jar:na]
... 37 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.validation.constraints.Min
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_211]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_211]
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_211]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_211]
... 54 common frames omitted
分析错误代码,查看关键的几句报错信息:
org.springframework.context.ApplicationContextException:
Failed to start bean 'documentationPluginsBootstrapper';
nested exception is com.google.common.util.concurrent.ExecutionError:
com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError:
javax/validation/constraints/Min
Caused by: java.lang.NoClassDefFoundError: javax/validation/constraints/Min
(2)解决方法
添加validation依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
再次启动项目即可。
打开浏览器,访问:http://localhost:8080/swagger-ui.html,即可查看swagger API文档。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/134799.html