Feign:文件上传配置

Feign : file upload configuration

我找到了使用 Feign 上传文件的解决方案,但我的配置产生了另一个问题。我有几个 Feign 客户端用于从客户端服务使用的不同服务。

现在,当我提交一个简单的表单时,我得到了这个错误:

feign.codec.EncodeException: class java.util.ArrayList is not a type supported by this encoder

在我有这个配置之前工作得很好但现在不行了,我不知道为什么。

@Component
@RestController
@FeignClient(name = "zuul-server"
,configuration = {ProxyImages.MultipartSupportConfig.class})
@RibbonClient(name = "oauth2-server")
public interface ProxyImages {

    class MultipartSupportConfig {
        @Bean
        @Primary
        @Scope("prototype")
        public Encoder feignFormEncoder() {
            return new SpringFormEncoder();
        }
    }

    @RequestMapping(value = {"oauth2-server/auth/user/avatar"}, consumes = {"multipart/form-data"})
    ResponseEntity<String> saveUserAvatar(@RequestPart(name = "file") MultipartFile file);$

}

我不知道为什么不再考虑 MultipartSupportConfig class。 所以我在 MultipartSupportConfig class

中添加了一个 @configuration 注释
  @Configuration
    class MultipartSupportConfig

它再次工作,但现在似乎总是使用此编码器,我只想将它用于该代理。我该怎么做?

这是我使用的依赖项

  <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.M8</spring-cloud.version>
        <joinfaces.version>3.2.4</joinfaces.version>

    </properties>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>io.github.openfeign.form</groupId>
            <artifactId>feign-form-spring</artifactId>
            <version>3.3.0</version>
        </dependency>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

谢谢。

问题已解决。

@RestController
@FeignClient(name = "zuul-server")
public interface ProxyImages {

    @Configuration
    class MultipartSupportConfig {

        @Autowired
        private ObjectFactory<HttpMessageConverters> messageConverters;

        @Bean
        @Primary
        @Scope("prototype")
        public Encoder feignFormEncoder() {
            return new SpringFormEncoder(new SpringEncoder(messageConverters));
        }
    }

    @RequestMapping(value = {"oauth2-server/auth/user/avatar"}, consumes = {"multipart/form-data"})
    ResponseEntity<String> saveUserAvatar(@RequestPart(name = "file") MultipartFile file);
}