33import cn .netbuffer .springboot .demo .decorator .HttpTaskDecorator ;
44import lombok .extern .slf4j .Slf4j ;
55import org .springframework .aop .interceptor .AsyncExecutionAspectSupport ;
6+ import org .springframework .beans .factory .annotation .Value ;
67import org .springframework .boot .actuate .trace .http .HttpTraceRepository ;
78import org .springframework .boot .actuate .trace .http .InMemoryHttpTraceRepository ;
89import org .springframework .context .annotation .Bean ;
1112import org .springframework .http .MediaType ;
1213import org .springframework .scheduling .concurrent .ThreadPoolTaskExecutor ;
1314import org .springframework .web .servlet .config .annotation .ContentNegotiationConfigurer ;
15+ import org .springframework .web .servlet .config .annotation .ResourceHandlerRegistry ;
1416import org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
1517import java .util .concurrent .ThreadPoolExecutor ;
1618
1719@ Slf4j
1820@ Configuration
1921public class WebMvcConfig implements WebMvcConfigurer {
2022
23+ @ Value ("${extra-static.file-path1}" )
24+ private String filePath1 ;
25+
26+ @ Value ("${extra-static.file-path2}" )
27+ private String filePath2 ;
28+
2129 @ Bean (name = AsyncExecutionAspectSupport .DEFAULT_TASK_EXECUTOR_BEAN_NAME )
2230 public AsyncTaskExecutor buildAsyncTaskExecutor () {
2331 log .info ("buildAsyncTaskExecutor" );
@@ -58,4 +66,13 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
5866 .defaultContentType (MediaType .APPLICATION_JSON );
5967 }
6068
61- }
69+ @ Override
70+ public void addResourceHandlers (ResourceHandlerRegistry registry ) {
71+ log .info ("bind static path /uploads1/** to file path:{}" , filePath1 );
72+ log .info ("bind static path /uploads2/** to file path:{}" , filePath2 );
73+ String filePrefix = "file:" ;
74+ registry .addResourceHandler ("/uploads1/**" ).addResourceLocations (filePrefix + filePath1 );
75+ registry .addResourceHandler ("/uploads2/**" ).addResourceLocations (filePrefix + filePath2 );
76+ }
77+
78+ }
0 commit comments