In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the Spring Boot 2.6.x integration of Swagger startup failure report how to solve the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this Spring Boot 2.6.x integration Swagger startup failure report how to solve the article will have something to gain, let's take a look.
problem
When dependency springfox-boot-starter (Swagger 3.0) is introduced in Spring Boot 2.6.x, the startup container will report an error:
Failed to start bean 'documentationPluginsBootstrapper'; nested exception...
Reason
Springfox assumes that the path matching policy for Spring MVC is ant-path-matcher, while the default matching policy for version 2.6.x of Spring Boot is path-pattern-matcher, which results in the above error.
Solution 1 (temporary treatment)
Modify the matching policy for mvc in the application.properties configuration file:
Spring.mvc.pathmatch.matching-strategy=ant-path-matcher
Note: I did start normally with this method at first, but then I found that this method will fail when some services are started! I checked and found that this method treats the symptoms rather than the root of the disease, as follows:
This feature works only if you are not using Spring Boot's actuators.
Regardless of the configured matching policy, the executor will always use path pattern-based resolution (that is, the default policy).
If you want to use it with the actuator in Spring Boot 2.6 and later, you need to make changes to Springfox.
So you have to tie the bell! To completely solve this bug, what needs to be modified is Springfox.
Option 2 (radical cure)
I found this solution on github. One boss proposed a solution to copy a .java file of Springfox into his own project for modification, while another boss proposed a better solution. I think the needle is not poked. Share it here:
Add this bean to your project: (just add it to the configuration class)
@ Beanpublic static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor () {return new BeanPostProcessor () {@ Override public Object postProcessAfterInitialization (Object bean, String beanName) throws BeansException {if (bean instanceof WebMvcRequestHandlerProvider | | bean instanceof WebFluxRequestHandlerProvider) {customizeSpringfoxHandlerMappings (getHandlerMappings (bean));} return bean } private void customizeSpringfoxHandlerMappings (List mappings) {List copy = mappings.stream () .filter (mapping-> mapping.getPatternParser () = = null) .filter (Collectors.toList ()); mappings.clear (); mappings.addAll (copy) } @ SuppressWarnings ("unchecked") private List getHandlerMappings (Object bean) {try {Field field = ReflectionUtils.findField (bean.getClass (), "handlerMappings"); field.setAccessible (true); return (List) field.get (bean);} catch (IllegalArgumentException | IllegalAccessException e) {throw new IllegalStateException (e) }
OK, start successfully!
Add: springboot integrates swagger and throws the following error when starting:
18Rom 03RV 03.586 [main] INFO o.s.b.a.l.ConditionEvaluationReportLoggingListener-
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
18Rom 03Rose 03.601 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter-
* *
APPLICATION FAILED TO START
* *
Description:
Parameter 0 of method linkDiscoverers in org.springframework.hateoas.config.HateoasConfiguration required a single bean, but 15 were found:
-modelBuilderPluginRegistry: defined in null
-modelPropertyBuilderPluginRegistry: defined in null
-typeNameProviderPluginRegistry: defined in null
-documentationPluginRegistry: defined in null
-apiListingBuilderPluginRegistry: defined in null
-operationBuilderPluginRegistry: defined in null
-parameterBuilderPluginRegistry: defined in null
-expandedParameterBuilderPluginRegistry: defined in null
-resourceGroupingStrategyRegistry: defined in null
-operationModelsProviderPluginRegistry: defined in null
-defaultsProviderPluginRegistry: defined in null
-pathDecoratorRegistry: defined in null
-relProviderPluginRegistry: defined by method 'relProviderPluginRegistry' in class path resource [org/springframework/hateoas/config/HateoasConfiguration.class]
-linkDiscovererRegistry: defined in null
-entityLinksPluginRegistry: defined by method 'entityLinksPluginRegistry' in class path resource [org/springframework/hateoas/config/WebMvcEntityLinksConfiguration.class]
Reason:
There is a problem with the swagger version. My local springboot version is 2.3.1, and the reference swaggerb version is 2.2.2, which causes the project to fail to start.
Solution:
Replace the swagger version. I changed it to version 2.9.2 here, and the project started successfully.
Io.springfox springfox-swagger2 2.9.2 io.springfox springfox-swagger-ui 2.9.2 on "Spring Boot 2.6.x Integration Swagger startup failure error report how to solve" this article is introduced here, thank you for reading! I believe that everyone has a certain understanding of "Spring Boot 2.6.x integration Swagger startup failure report how to solve" knowledge, if you want to learn more knowledge, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.