org.zodiac.autoconfigure.boot.reactive.PlatformMultipartUploadRectiveAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.boot.reactive;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;
import org.zodiac.autoconfigure.boot.PlatformUploadFileProperties;
import org.zodiac.autoconfigure.boot.condition.ConditionalOnMultipartUploadEnabled;
import org.zodiac.boot.resolver.ReactiveTokenArgumentResolver;
@Order(value = Ordered.HIGHEST_PRECEDENCE)
@SpringBootConfiguration
@ConditionalOnMultipartUploadEnabled
@ConditionalOnWebApplication(type = Type.REACTIVE)
@ConditionalOnClass(value = {org.zodiac.boot.config.PlatformUploadFileInfo.class, org.springframework.web.server.WebHandler.class, org.springframework.web.reactive.DispatcherHandler.class})
public class PlatformMultipartUploadRectiveAutoConfiguration implements WebFluxConfigurer {
private final PlatformUploadFileProperties platformUploadFileProperties;
public PlatformMultipartUploadRectiveAutoConfiguration(PlatformUploadFileProperties platformUploadFileProperties) {
this.platformUploadFileProperties = platformUploadFileProperties;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String path = platformUploadFileProperties.getSavePath();
registry.addResourceHandler(String.format("%s/**", platformUploadFileProperties.getUploadPath())).addResourceLocations(String.format("file:%s%s/", path, platformUploadFileProperties.getUploadPath()));
}
@Override
public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
configurer.addCustomResolver(new ReactiveTokenArgumentResolver());
}
}