jtoms 4 jaren geleden
bovenliggende
commit
c927a07684

+ 1 - 0
.gitignore

@@ -5,3 +5,4 @@ core/target
 sample/target
 target/
 /src/main/resources/public/
+/LOGGER_ROOT_PATH_IS_UNDEFINED/

+ 0 - 8
src/main/java/com/zhiqiyun/open/Application.java

@@ -1,23 +1,15 @@
 package com.zhiqiyun.open;
 
 import lombok.extern.slf4j.Slf4j;
-import org.lionsoul.ip2region.DbConfig;
-import org.lionsoul.ip2region.DbSearcher;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.web.servlet.ServletComponentScan;
-import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-
 /**
  * @author stjdydayou
  */
 @Slf4j
 @Configuration
-@ServletComponentScan
 @SpringBootApplication
 public class Application {
 

+ 14 - 4
src/main/java/com/zhiqiyun/open/config/WebMvcConfig.java

@@ -18,8 +18,9 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
 import org.springframework.lang.NonNull;
 import org.springframework.web.servlet.HandlerInterceptor;
 import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -33,12 +34,18 @@ import java.util.List;
  */
 @Slf4j
 @Configuration
-public class WebMvcConfig implements WebMvcConfigurer {
+public class WebMvcConfig extends DelegatingWebMvcConfiguration {
 
     @Autowired
     private OauthInterceptor oauthInterceptor;
 
     @Override
+    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
+        registry.addResourceHandler("/**").addResourceLocations("classpath:/public/");
+        super.addResourceHandlers(registry);
+    }
+
+    @Override
     public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
         converters.removeIf(converter -> converter instanceof MappingJackson2HttpMessageConverter);
         ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
@@ -61,6 +68,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
         MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper);
         converters.add(converter);
         log.info("{}", converters.size());
+        super.configureMessageConverters(converters);
     }
 
 
@@ -77,8 +85,9 @@ public class WebMvcConfig implements WebMvcConfigurer {
             public void afterCompletion(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull Object handler, Exception ex) {
                 ServletContext.clean();
             }
-        }).addPathPatterns("/**");
-        registry.addInterceptor(this.oauthInterceptor).addPathPatterns("/**");
+        }).addPathPatterns("/**").excludePathPatterns("/static/**", "/index.html");
+        registry.addInterceptor(this.oauthInterceptor).addPathPatterns("/**").excludePathPatterns("/static/**", "/index.html");
+        super.addInterceptors(registry);
     }
 
     @Override
@@ -88,6 +97,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
                 .allowCredentials(true)
                 .allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH")
                 .maxAge(3600);
+        super.addCorsMappings(registry);
     }
 }
 

+ 10 - 17
src/main/java/com/zhiqiyun/open/mvc/manager/controller/IndexController.java

@@ -1,24 +1,17 @@
 package com.zhiqiyun.open.mvc.manager.controller;
 
-import com.zhiqiyun.open.core.service.Ip2RegionService;
-import com.zhiqiyun.open.core.service.SequenceService;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 
 @Slf4j
-@RestController
+@Controller
 public class IndexController {
-
-	@Autowired
-	private Ip2RegionService ip2RegionService;
-	@Autowired
-	private SequenceService sequenceService;
-
-	@RequestMapping(method = {RequestMethod.POST, RequestMethod.GET}, value = {"/", "/index", "/index.do"})
-	public Object index() {
-		return this.sequenceService.nextId();
-	}
+    @GetMapping("/")
+    public void index(HttpServletResponse response) throws IOException {
+        response.sendRedirect("/index.html");
+    }
 }