Commit 94bd886a95613687756f282adda58b86bbafafe5
1 parent
f6706f57
解决自定义拦截器不生效问题
Signed-off-by: TanYibin <5491541@qq.com>
Showing
2 changed files
with
16 additions
and
29 deletions
huaheng-wms-core/src/main/java/org/jeecg/utils/config/InterceptorAdapterConfig.java deleted
1 | -package org.jeecg.utils.config; | |
2 | - | |
3 | -import org.jeecg.utils.interceptor.AccessLimitInterceptor; | |
4 | -import org.springframework.beans.factory.annotation.Autowired; | |
5 | -import org.springframework.context.annotation.Configuration; | |
6 | -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | |
7 | -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; | |
8 | - | |
9 | -@Configuration | |
10 | -public class InterceptorAdapterConfig extends WebMvcConfigurationSupport { | |
11 | - @Autowired | |
12 | - private AccessLimitInterceptor accessLimitInterceptor; | |
13 | - | |
14 | - @Override | |
15 | - public void addInterceptors(InterceptorRegistry registry) { | |
16 | - // 注册自己的拦截器并设置拦截的请求路径 | |
17 | - registry.addInterceptor(accessLimitInterceptor).addPathPatterns("/**"); | |
18 | - super.addInterceptors(registry); | |
19 | - } | |
20 | -} | |
21 | 0 | \ No newline at end of file |
huaheng-wms-core/src/main/java/org/jeecg/utils/config/Swagger3Config.java
... | ... | @@ -4,11 +4,15 @@ import java.util.ArrayList; |
4 | 4 | import java.util.Collections; |
5 | 5 | import java.util.List; |
6 | 6 | |
7 | +import javax.annotation.Resource; | |
8 | + | |
7 | 9 | import org.jeecg.common.constant.CommonConstant; |
10 | +import org.jeecg.utils.interceptor.AccessLimitInterceptor; | |
8 | 11 | import org.springframework.context.annotation.Bean; |
9 | 12 | import org.springframework.context.annotation.Configuration; |
10 | 13 | import org.springframework.context.annotation.Import; |
11 | 14 | import org.springframework.web.bind.annotation.RestController; |
15 | +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | |
12 | 16 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
13 | 17 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
14 | 18 | |
... | ... | @@ -34,6 +38,15 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; |
34 | 38 | @Import(BeanValidatorPluginsConfiguration.class) |
35 | 39 | public class Swagger3Config implements WebMvcConfigurer { |
36 | 40 | |
41 | + @Resource | |
42 | + private AccessLimitInterceptor accessLimitInterceptor; | |
43 | + | |
44 | + @Override | |
45 | + public void addInterceptors(InterceptorRegistry registry) { | |
46 | + // 注册自己的拦截器并设置拦截的请求路径 | |
47 | + registry.addInterceptor(accessLimitInterceptor).addPathPatterns("/**").excludePathPatterns("/static/**"); | |
48 | + } | |
49 | + | |
37 | 50 | /** |
38 | 51 | * 显示swagger-ui.html文档展示页,还必须注入swagger资源: |
39 | 52 | * @param registry |
... | ... | @@ -51,16 +64,10 @@ public class Swagger3Config implements WebMvcConfigurer { |
51 | 64 | */ |
52 | 65 | @Bean(value = "defaultApi2") |
53 | 66 | public Docket defaultApi2() { |
54 | - return new Docket(DocumentationType.SWAGGER_2) | |
55 | - .apiInfo(apiInfo()) | |
56 | - .select() | |
57 | - .apis(RequestHandlerSelectors.basePackage("org.jeecg.modules.wms.api"))// 此包路径下的类,才生成接口文档 | |
67 | + return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("org.jeecg.modules.wms.api"))// 此包路径下的类,才生成接口文档 | |
58 | 68 | .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))// 加了ApiOperation注解的类,才生成接口文档 |
59 | - .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) | |
60 | - .paths(PathSelectors.any()) | |
61 | - .build() | |
62 | - .securitySchemes(Collections.singletonList(securityScheme())) | |
63 | - .securityContexts(securityContexts()); | |
69 | + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).paths(PathSelectors.any()).build() | |
70 | + .securitySchemes(Collections.singletonList(securityScheme())).securityContexts(securityContexts()); | |
64 | 71 | // .globalOperationParameters(setHeaderToken()); |
65 | 72 | } |
66 | 73 | |
... | ... |