Java 使用Spring引导和Open-feign将多部分文件发送到restapi时出错

Java 使用Spring引导和Open-feign将多部分文件发送到restapi时出错,java,spring,spring-boot,groovy,openfeign,Java,Spring,Spring Boot,Groovy,Openfeign,我正在尝试将要发送到的文件作为多部分文件附加到端点,但出现以下异常: Expected no exception to be thrown, but got 'feign.codec.EncodeException' //... Caused by: feign.codec.EncodeException: Could not write request: no suitable HttpMessageConverter found for request type [java.util.Li

我正在尝试将要发送到的文件作为
多部分文件附加到端点
,但出现以下异常:

Expected no exception to be thrown, but got 'feign.codec.EncodeException'
//...
Caused by: feign.codec.EncodeException: Could not write request: 
no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap] 
and content type [multipart/form-data]
Cannot cast object 'feign.form.FormEncoder@5fa78e0a' 
with class 'feign.form.FormEncoder' to class 'java.beans.Encoder'
我的方法是:

//...
final User user
//...
@Override
DocumentResponse attachDocument(File file, String userId, String documentId) {

    String timestamp = String.valueOf(System.currentTimeMillis())
    String url = "${myProperties.apiUrl}/documents/attach?ts=${timestamp}"
    String digest = myJWT.sign(HttpMethod.POST, url)

    MultipartFile multiFile = new MockMultipartFile("test.xml", 
        new FileInputStream(file))

    DocumentResponse documentResponse = user.attachDocument(multiFile, 
        userId, documentId, timestamp, digest)

    return documentResponse
}
我的界面是:

@FeignClient(name = 'myUser', url = '${apiUrl}', configuration = myConfiguration)
interface User {

    //...

    @PostMapping(value = '/documents/attach', consumes = 'multipart/form-data')
    DocumentResponse attachDocument(@PathVariable('file') MultipartFile multiFile,
                                  @PathVariable('clientId') String userId,
                                  @PathVariable('documentId') String documentId,
                                  @RequestParam('ts') String timestamp,
                                  @RequestParam('digest') String digest)

}
我的配置文件是:

@Slf4j
@Configuration
class myConfiguration {

    @Bean
    Retryer feignRetryer(@Value('${feign.client.config.myUser.period}') Long period,
                     @Value('${feign.client.config.myUser.maxInterval}') Long maxInterval,
                     @Value('${feign.client.config.myUser.maxAttempts}') Integer maxAttempts) {
         return new Retryer.Default(period, maxInterval, maxAttempts)
    }

    @Bean
    ErrorDecoder errorDecoder() {
        return new ErrorDecoder() {
            @Override
            Exception decode(String methodKey, Response response) {
                if (HttpStatus.OK.value() != response.status()) {
                    FeignException ex = FeignException.errorStatus(methodKey, response)
                    if (response.status() != HttpStatus.BAD_REQUEST.value()) {
                        return new RetryableException('getting conflict and retry', new Date(System.currentTimeMillis() + TimeUnit.SECONDS
                        .toMillis(1)))
                     }
                     return new MyDocumentException()
                }
            }
        }
    }
}
此外,我还尝试将以下代码添加到myConfiguration文件:

@Bean
Encoder encoder() {
    return new FormEncoder()
}
但我还有一个例外:

Expected no exception to be thrown, but got 'feign.codec.EncodeException'
//...
Caused by: feign.codec.EncodeException: Could not write request: 
no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap] 
and content type [multipart/form-data]
Cannot cast object 'feign.form.FormEncoder@5fa78e0a' 
with class 'feign.form.FormEncoder' to class 'java.beans.Encoder'
我正在使用Spring boot
'2.0.2.RELEASE'
,它包括:

"io.github.openfeign.form:feign-form:3.4.1",
"io.github.openfeign.form:feign-form-spring:3.4.1",
我查看了这些帖子:


有什么建议吗?

当编码邮件时出现问题时,会引发.codec.EncodeException异常。
我认为
@PathVariable('file')MultipartFile multiFile
,可以转换为base64 sting并将其传递给REST API,或者向
MultipartFile添加一个编码器

API只接受内容类型:multipart/form data;boundary=“这里的边界”所以我认为问题在于如何正确使用编码器。@Javier C你得到答案了吗?如果是,请在这里发布。@kashiviswanath不抱歉,我没有找到解决方案