|
18 | 18 | package org.apache.shenyu.examples.http.config; |
19 | 19 |
|
20 | 20 | import io.swagger.annotations.ApiOperation; |
21 | | -import java.lang.reflect.Field; |
22 | | -import java.util.ArrayList; |
23 | | -import java.util.List; |
24 | | -import java.util.Objects; |
25 | | -import java.util.stream.Collectors; |
26 | 21 | import org.apache.shenyu.common.constant.Constants; |
27 | 22 | import org.apache.shenyu.common.utils.VersionUtils; |
28 | | -import org.springframework.beans.BeansException; |
29 | | -import org.springframework.beans.factory.config.BeanPostProcessor; |
30 | 23 | import org.springframework.context.annotation.Bean; |
31 | 24 | import org.springframework.context.annotation.Configuration; |
32 | | -import org.springframework.util.ReflectionUtils; |
33 | | -import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; |
34 | 25 | import springfox.documentation.builders.ApiInfoBuilder; |
35 | 26 | import springfox.documentation.builders.ParameterBuilder; |
36 | 27 | import springfox.documentation.builders.PathSelectors; |
|
41 | 32 | import springfox.documentation.service.Parameter; |
42 | 33 | import springfox.documentation.spi.DocumentationType; |
43 | 34 | import springfox.documentation.spring.web.plugins.Docket; |
44 | | -import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider; |
45 | | -import springfox.documentation.swagger2.annotations.EnableSwagger2; |
| 35 | +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; |
| 36 | + |
| 37 | +import java.util.ArrayList; |
| 38 | +import java.util.List; |
46 | 39 |
|
47 | 40 | /** |
48 | 41 | * Configuration class for Swagger API document. |
49 | 42 | */ |
50 | 43 | @Configuration |
51 | | -@EnableSwagger2 |
| 44 | +@EnableSwagger2WebMvc |
52 | 45 | public class SwaggerConfiguration { |
53 | 46 |
|
54 | 47 | private static final String DEFAULT_SWAGGER_API_VERSION = "2.3.0"; |
@@ -103,44 +96,44 @@ public Docket createRestApi() { |
103 | 96 | .build(); |
104 | 97 | } |
105 | 98 |
|
106 | | - /** |
107 | | - * use bean to be compatible with springboot 2.6.8. |
108 | | - * |
109 | | - * @return BeanPostProcessor |
110 | | - */ |
111 | | - @Bean |
112 | | - public BeanPostProcessor springfoxBeanHandler() { |
113 | | - return new BeanPostProcessor() { |
114 | | - @Override |
115 | | - public Object postProcessAfterInitialization(final Object bean, |
116 | | - final String beanName) throws BeansException { |
117 | | - if (bean instanceof WebMvcRequestHandlerProvider) { |
118 | | - customizeSpringfoxHandlerMappings(getHandlerMappings(bean)); |
119 | | - } |
120 | | - return bean; |
121 | | - } |
122 | | - |
123 | | - private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings( |
124 | | - final List<T> mappings) { |
125 | | - List<T> copy = mappings.stream() |
126 | | - .filter(mapping -> Objects.isNull(mapping.getPatternParser())) |
127 | | - .collect(Collectors.toList()); |
128 | | - mappings.clear(); |
129 | | - mappings.addAll(copy); |
130 | | - } |
131 | | - |
132 | | - @SuppressWarnings("unchecked") |
133 | | - private List<RequestMappingInfoHandlerMapping> getHandlerMappings(final Object bean) { |
134 | | - try { |
135 | | - Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings"); |
136 | | - field.setAccessible(true); |
137 | | - return (List<RequestMappingInfoHandlerMapping>) field.get(bean); |
138 | | - } catch (IllegalArgumentException | IllegalAccessException e) { |
139 | | - throw new IllegalStateException(e); |
140 | | - } |
141 | | - } |
142 | | - }; |
143 | | - } |
| 99 | +// /** |
| 100 | +// * use bean to be compatible with springboot 2.6.8. |
| 101 | +// * |
| 102 | +// * @return BeanPostProcessor |
| 103 | +// */ |
| 104 | +// @Bean |
| 105 | +// public BeanPostProcessor springfoxBeanHandler() { |
| 106 | +// return new BeanPostProcessor() { |
| 107 | +// @Override |
| 108 | +// public Object postProcessAfterInitialization(final Object bean, |
| 109 | +// final String beanName) throws BeansException { |
| 110 | +// if (bean instanceof WebMvcRequestHandlerProvider) { |
| 111 | +// customizeSpringfoxHandlerMappings(getHandlerMappings(bean)); |
| 112 | +// } |
| 113 | +// return bean; |
| 114 | +// } |
| 115 | +// |
| 116 | +// private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings( |
| 117 | +// final List<T> mappings) { |
| 118 | +// List<T> copy = mappings.stream() |
| 119 | +// .filter(mapping -> Objects.isNull(mapping.getPatternParser())) |
| 120 | +// .collect(Collectors.toList()); |
| 121 | +// mappings.clear(); |
| 122 | +// mappings.addAll(copy); |
| 123 | +// } |
| 124 | +// |
| 125 | +// @SuppressWarnings("unchecked") |
| 126 | +// private List<RequestMappingInfoHandlerMapping> getHandlerMappings(final Object bean) { |
| 127 | +// try { |
| 128 | +// Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings"); |
| 129 | +// field.setAccessible(true); |
| 130 | +// return (List<RequestMappingInfoHandlerMapping>) field.get(bean); |
| 131 | +// } catch (IllegalArgumentException | IllegalAccessException e) { |
| 132 | +// throw new IllegalStateException(e); |
| 133 | +// } |
| 134 | +// } |
| 135 | +// }; |
| 136 | +// } |
144 | 137 |
|
145 | 138 | /** |
146 | 139 | * Fetch version information from pom.xml and set title, version, description, |
|
0 commit comments