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();
}
}