Explorar el Código

提交配置文件

xusonglin hace 5 años
padre
commit
c3fb14cabd

+ 0 - 31
src/main/java/com/jkcredit/sysnews/config/CorsConfig.java

@@ -43,35 +43,4 @@ public class CorsConfig implements WebMvcConfigurer {
                 .allowedMethods("GET", "POST")
                 .maxAge(3600);
     }
-
-    @Override
-    public void addResourceHandlers(ResourceHandlerRegistry registry) {
-        registry.addResourceHandler("/app/image/**").addResourceLocations("file:/home/jknews/news/photo/");
-    }
-
-
-    //http://127.0.0.1:8081/app/page/newsArticles
-    //http://127.0.0.1:8081/app/photo/upload
-    //http://127.0.0.1:8081/app/images/202003091435211231234.png
-    //http://127.0.0.1:8081/app/images/202003091435211231235.png
-    //http://127.0.0.1:8081/app/images/202003091435211231236.png
-
-    /*
-    application.properties
-    jkcredit.news.images.upload.path=/home/news/beans/photo
-    jkcredit.news.images.virthr.path=/home/news/beans/photo
-    jkcredit.news.access.url=https://127.0.0.1:8081
-    jkcredit.news.access.url=https://news.jkcredit.cn
-
-
-
-
-    File mkdir upload.path
-    IMAGE /201.png
-    ${jkcredit.news.access.url}${/app/images}/201.png
-
-
-
-     */
-
 }

+ 35 - 13
src/main/java/com/jkcredit/sysnews/config/WebConfiguration.java

@@ -2,10 +2,17 @@ package com.jkcredit.sysnews.config;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
 @Configuration
-public class WebConfiguration {
+public class WebConfiguration implements WebMvcConfigurer {
+    @Value("${photo.accessResource}")
+    private String accessResource;
+    @Value("${photo.veritablePath}")
+    private String veritablePath;
 
     private final Logger log = LoggerFactory.getLogger(WebConfiguration.class);
 
@@ -15,17 +22,32 @@ public class WebConfiguration {
         this.applicationProperties = applicationProperties;
     }
 
-//    @Bean
-//    public CorsFilter corsFilter() {
-//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
-//        CorsConfiguration config = applicationProperties.getCors();
-//        if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) {
-//            log.info("Registering CORS filter");
-//            source.registerCorsConfiguration("/api/**", config);
-//            source.registerCorsConfiguration("/management/**", config);
-//            source.registerCorsConfiguration("/v2/api-docs", config);
-//        }
-//        return new CorsFilter(source);
-//    }
+    @Override
+    public void addResourceHandlers(ResourceHandlerRegistry registry) {
+        registry.addResourceHandler(accessResource + "**").addResourceLocations(veritablePath);
+    }
+    //http://127.0.0.1:8081/app/page/newsArticles
+    //http://127.0.0.1:8081/app/photo/upload
+    //http://127.0.0.1:8081/app/images/202003091435211231234.png
+    //http://127.0.0.1:8081/app/images/202003091435211231235.png
+    //http://127.0.0.1:8081/app/images/202003091435211231236.png
+
+    /*
+    application.properties
+    jkcredit.news.images.upload.path=/home/news/beans/photo
+    jkcredit.news.images.virthr.path=/home/news/beans/photo
+    jkcredit.news.access.url=https://127.0.0.1:8081
+    jkcredit.news.access.url=https://news.jkcredit.cn
+
+
+
+
+    File mkdir upload.path
+    IMAGE /201.png
+    ${jkcredit.news.access.url}${/app/images}/201.png
+
+
+
+     */
 
 }

+ 1 - 1
src/main/resources/application-prod.yml

@@ -11,6 +11,6 @@ mybatis-plus:
   mapper-locations: classpath:mapper/*Mapper.xml
 photo:
   uploadPath: /home/jknews/news/photo
-  veritablePath: /home/jknews/news/photo
+  veritablePath: file:/home/jknews/news/photo/
   accessPath: http://192.168.1.199:18083
   accessResource: /app/image/