From 781c0462c34b22ad5f3635ce49a5aef6136d0003 Mon Sep 17 00:00:00 2001 From: xiangwb Date: Tue, 7 Nov 2017 17:30:08 +0800 Subject: [PATCH] merge --- .../DispatcherServletConfig.java | 38 +++++++++++-------- .../xwbing/configuration/SwaggerConfig.java | 5 +-- .../com/xwbing/handler/LoginInterceptor.java | 9 ++++- pom.xml | 2 +- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/boot-web/src/main/java/com/xwbing/configuration/DispatcherServletConfig.java b/boot-web/src/main/java/com/xwbing/configuration/DispatcherServletConfig.java index 74ac8c8..ffee7ff 100644 --- a/boot-web/src/main/java/com/xwbing/configuration/DispatcherServletConfig.java +++ b/boot-web/src/main/java/com/xwbing/configuration/DispatcherServletConfig.java @@ -1,6 +1,7 @@ package com.xwbing.configuration; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; +import com.xwbing.handler.LoginInterceptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Bean; @@ -9,7 +10,10 @@ import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.multipart.commons.CommonsMultipartResolver; -import org.springframework.web.servlet.config.annotation.*; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import javax.servlet.Filter; import java.util.ArrayList; @@ -35,25 +39,29 @@ public class DispatcherServletConfig extends WebMvcConfigurerAdapter { public void addInterceptors(InterceptorRegistry registry) { logger.info("addInterceptors......"); //拦截器1:登录判断 -// registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**"); + registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**"); // registry.addInterceptor(new LoginInterceptor()) -// .addPathPatterns("/**").excludePathPatterns("/user/login", "/servlet/captchaCode", "/doc.html", "/swagger-ui.html"); +// .addPathPatterns("/**").excludePathPatterns("/user/login", "/servlet/captchaCode", "/swagger-ui.html"); //拦截器2... super.addInterceptors(registry); } - // /** -// * 配置静态访问资源 -// * @param registry -// */ -// @Override -// public void addResourceHandlers(ResourceHandlerRegistry registry) { -// registry.addResourceHandler("swagger-ui.html") -// .addResourceLocations("classpath:/META-INF/resources/"); -// registry.addResourceHandler("/webjars/**") -// .addResourceLocations("classpath:/META-INF/resources/webjars/"); -// super.addResourceHandlers(registry); -// } + /** + * 配置静态访问资源 + * 默认: + * classpath:/static + * classpath:/public + * classpath:/resources + * classpath:/META-INF/resources + * + * @param registry + */ + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); + registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); + super.addResourceHandlers(registry); + } /** * 扩展消息转换器,增加fastjson diff --git a/boot-web/src/main/java/com/xwbing/configuration/SwaggerConfig.java b/boot-web/src/main/java/com/xwbing/configuration/SwaggerConfig.java index 072cb65..857d88d 100644 --- a/boot-web/src/main/java/com/xwbing/configuration/SwaggerConfig.java +++ b/boot-web/src/main/java/com/xwbing/configuration/SwaggerConfig.java @@ -22,7 +22,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @EnableSwagger2 public class SwaggerConfig { @Bean - public Docket buildDocket(){ + public Docket buildDocket() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(buildApiInf()) .select() @@ -31,7 +31,7 @@ public class SwaggerConfig { .build(); } - private ApiInfo buildApiInf(){ + private ApiInfo buildApiInf() { return new ApiInfoBuilder() .title("Document RESTful APIs") .description("API接口文档") @@ -40,5 +40,4 @@ public class SwaggerConfig { .version("1.0.0") .build(); } - } diff --git a/boot-web/src/main/java/com/xwbing/handler/LoginInterceptor.java b/boot-web/src/main/java/com/xwbing/handler/LoginInterceptor.java index 2140133..c6386ef 100644 --- a/boot-web/src/main/java/com/xwbing/handler/LoginInterceptor.java +++ b/boot-web/src/main/java/com/xwbing/handler/LoginInterceptor.java @@ -26,9 +26,14 @@ public class LoginInterceptor extends HandlerInterceptorAdapter { private static final Set set = new HashSet<>();//拦截器白名单 static { - set.add("/v2/api-docs"); + //验证码 set.add("/servlet/captchaCode"); - set.add("/swagger-ui.html"); + //swagger + set.add("/v2/api-docs"); + set.add("/swagger-resources"); + set.add("/configuration/ui"); + set.add("/configuration/security"); + // } @Override diff --git a/pom.xml b/pom.xml index b75e9b9..d44ade2 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ com.alibaba fastjson - 1.1.41 + 1.2.8 com.google.code.gson