我在应用中创建了@FeignCleint
,并具有以下映射:
@FeignClient(name="${mongo.service.id}", url="${mongo.service.url}")
public interface MongoBusinessDayDataInterface {
String requestMappingPrefix = "/api/businessDayData";
@GetMapping(path = {requestMappingPrefix + "/{businessDate}",
requestMappingPrefix + "/{businessDate}/{terminalId}",
requestMappingPrefix + "/{businessDate}/{currency}",
requestMappingPrefix + "/{businessDate}/{terminalId}/{currency}"})
BusinessDayData fetchBusinessDayData(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate businessDate,
@PathVariable(required = false) String terminalId,
@PathVariable(required = false) CurrencyType currency);
}
当我尝试加载应用程序时,出现以下异常:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'com.poalim.dc.atm.reconciliation.rest.feign.service.MongoBusinessDayDataInterface':
FactoryBean threw exception on object creation;
nested exception is java.lang.IllegalStateException:
Method fetchBusinessDayDataList can only contain at most 1 value field.
Found: [/api/businessDayData/list/{businessDate}, /api/businessDayData/list/{businessDate}/{terminalId}, /api/businessDayData/list/{businessDate}/{currency}, /api/businessDayData/list/{businessDate}/{terminalId}/{currency}]
如果path属性可以接收字符串数组,为什么会说它“最多只能包含1个值字段”?
[@GetMapping
是Spring Web模块的注释,通常在服务器应用程序的控制器中使用。
默认情况下,Feign不支持此类注释。它具有its own set of them。例如,@RequestLine
仅支持一个路径。
spring-cloud-openfeign
添加了额外的支持,以纯粹为开发人员的方便(针对SpringMvcContract)为假冒客户使用spring-web的注释。但是,在这种情况下,某些注释的签名不匹配在这种情况下应忽略。
顺便说一句,使用Feign时设置多个路径在逻辑上是毫无意义的。它是一个客户端,因此当您通过它发出请求时,它应该知道应该选择哪个路径。