Selaa lähdekoodia

允许swagger通过

lrf 9 kuukautta sitten
vanhempi
commit
cd5ef089a5

+ 12 - 2
src/main/java/com/free/InterceptorConfig.java

@@ -3,6 +3,7 @@ package com.free;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
 import com.free.frame.AuthenticationInterceptor;
@@ -11,12 +12,21 @@ import com.free.frame.AuthenticationInterceptor;
 public class InterceptorConfig implements WebMvcConfigurer {
   @Override
   public void addInterceptors(InterceptorRegistry registry) {
-    registry.addInterceptor(authenticationInterceptor()).excludePathPatterns("/kf/login/**", "/kf/logout")
-        .addPathPatterns("/**");
+    registry.addInterceptor(authenticationInterceptor())
+        .addPathPatterns("/**")
+        .excludePathPatterns("/kf/login/**", "/kf/logout", "/swagger**/**", "/webjars/**", "/v3/**", "/doc.html");
+  }
+
+  @Override
+  public void addResourceHandlers(ResourceHandlerRegistry registry) {
+
+    registry.addResourceHandler("/swagger-ui/**")
+        .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
   }
 
   @Bean
   public AuthenticationInterceptor authenticationInterceptor() {
     return new AuthenticationInterceptor();
   }
+
 }

+ 7 - 5
src/main/java/com/free/Main.java

@@ -5,11 +5,13 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.ComponentScan;
 
-@MapperScan({"com.free.mapper","com.gitee.sunchenbin.mybatis.actable.dao.*"})
-@ComponentScan(basePackages = {"com.free","com.gitee.sunchenbin.mybatis.actable.manager.*"})
+@MapperScan({ "com.free.mapper", "com.gitee.sunchenbin.mybatis.actable.dao.*" })
+@ComponentScan(basePackages = { "com.free", "com.gitee.sunchenbin.mybatis.actable.manager.*" })
 @SpringBootApplication
 public class Main {
-    public static void main(String[] args) {
-        SpringApplication.run(Main.class, args);
-    }
+  public static void main(String[] args) {
+    SpringApplication.run(Main.class, args);
+    System.out.println("swagger:");
+    System.out.println("http://localhost:4001/swagger-ui/index.html");
+  }
 }