Browse Source

跨域问题

hcst_sunzhen 4 years ago
parent
commit
7eed09d590

+ 40 - 0
src/main/java/cn/com/ctop/okr/config/WebMvcConfiguration.java

@@ -1,10 +1,16 @@
 package cn.com.ctop.okr.config;
 
+import cn.com.ctop.okr.interceptors.BrowseLogHandelInterceptor;
+import cn.com.ctop.okr.utils.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.cors.CorsConfiguration;
 import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
 import org.springframework.web.filter.CorsFilter;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
 /**
@@ -15,6 +21,22 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  */
 @Configuration
 public class WebMvcConfiguration implements WebMvcConfigurer {
+
+	@Autowired
+	BrowseLogHandelInterceptor browseLogHandelInterceptor;
+
+	@Value("${jeecg.path.upload}")
+	private String upLoadPath;
+	@Value("${jeecg.path.webapp}")
+	private String webAppPath;
+	@Value("${spring.resource.static-locations}")
+	private String staticLocations;
+
+//	@Override
+//	public void addInterceptors(InterceptorRegistry registry) {
+//		registry.addInterceptor(browseLogHandelInterceptor);
+//	}
+
 	@Bean
 	public CorsFilter corsFilter() {
 		final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
@@ -30,4 +52,22 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
 		urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
 		return new CorsFilter(urlBasedCorsConfigurationSource);
 	}
+
+	/**
+	 * 静态资源的配置 - 使得可以从磁盘中读取 Html、图片、视频、音频等
+	 */
+	@Override
+	public void addResourceHandlers(ResourceHandlerRegistry registry) {
+		registry.addResourceHandler("/**")
+		.addResourceLocations("file:" + upLoadPath + "//", "file:" + webAppPath + "//")
+				.addResourceLocations(staticLocations.split(StringUtils.COMMA));
+	}
+
+	/**
+	 * 访问根路径默认跳转 index.html页面 (简化部署方案: 可以把前端打包直接放到项目的 webapp,上面的配置)
+	 */
+	@Override
+	public void addViewControllers(ViewControllerRegistry registry) {
+		registry.addViewController("/").setViewName("index.html");
+	}
 }

+ 17 - 0
src/main/resources/application.yml

@@ -132,4 +132,21 @@ xxl:
     admin:
       addresses: http://39.106.184.70:8090/xxl-job-admin
 
+#jeecg专用配置
+jeecg:
+  ffmpeg:
+    bin: ffmpeg
+  path:
+    #文件上传根目录 设置
+    upload: /data/upload
+    #webapp文件路径
+    webapp: /data/webapp
+    video-upload: /data/upload/video/
+    image-upload: /data/upload/image/
+    chrome-driver: /usr/bin/chromedriver
+    csv-upload: /data/upload/csv/
+    bak-database-file: /data/data/bak/
+    report-history: /data/upload/report/history/
+    report-daily: /data/upload/report/daily/
+