package com.quanwei.wlanscope_wechat_information_treasure.config;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @date 2019-8-21
*
* <p>微服务之间通过Feign进行文件互传的配置类</p>
* <p>添加feign的扩展包,并自定义编码</p>
*
* <p>添加依赖
* <!--开启feign(集成了ribbon和hystrix)-->
* <dependency>
* <groupId>org.springframework.cloud</groupId>
* <artifactId>spring-cloud-starter-openfeign</artifactId>
* </dependency>
* <!--feign底层替换httpClient-->
* <dependency>
* <groupId>io.github.openfeign</groupId>
* <artifactId>feign-httpclient</artifactId>
* </dependency>
* <!--feign扩展包版本太高 已经出现问题,此处使用3.0.3版本的-->
* <dependency>
* <groupId>io.github.openfeign.form</groupId>
* <artifactId>feign-form</artifactId>
* <version>3.0.3</version>
* </dependency>
* <dependency>
* <groupId>io.github.openfeign.form</groupId>
* <artifactId>feign-form-spring</artifactId>
* <version>3.0.3</version>
* </dependency>
* <p>
* </>
* <p>
* 调用示例
* @FeignClient(value = "wlanscope-oss-server")
* public interface TestUploadFileService {
* @PostMapping(value = "/oss-server/file/test-upload-file", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
* String test(@RequestPart("file") MultipartFile file);
* }
* <i> consumes = MediaType.MULTIPART_FORM_DATA_VALUE,此处必须指明类型</>
*
* <p>文件接收接口
* public String testAccecptFile(@RequestPart ("file")MultipartFile multipartFile)
* 如此接口即可
* </p>
*
* <p>
* 调用feign 接口示例
* public String test() {
* MultipartFile multipartFile = new MockMultipartFile("file", "123", MediaType.MULTIPART_FORM_DATA_VALUE, "234.txt".getBytes(StandardCharsets.UTF_8));
* <i>由于文件接收接口 固定参数为file,所以此处的第一个参数(文件名)必须为file</i>
* 构造函数列表含义:文件名(文件接收接口定义的参数名)、原始文件名、请求类型、文件内容
* String msg = testUploadFileService.test(multipartFile);
* return msg;
* }
*
* </p>
*/
@Configuration
public class MultipartSupportConfig {
@Bean
public Encoder feignFormEncoder() {
return new SpringFormEncoder();
}
}