我有这样的FeignClient
@RequestLine("POST /enroll")
@Headers({ "header1: {header1}", "header2: {header2}", "Content-Type: application/json" })
ResponseDto enroll(@Param("header1") String header1,@Param("header1") String header1, RequestDto requestDto)throws MyCustomException;
Run Code Online (Sandbox Code Playgroud)
`我没有使用spring cloud netflix.但我一直得到以下例外.
Caused by: java.lang.IllegalStateException: Body parameters cannot be used with form parameters.
at feign.Util.checkState(Util.java:128)
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:112)
at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:64)
at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:146)
at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:53)
at feign.Feign$Builder.target(Feign.java:209)
at feign.Feign$Builder.target(Feign.java:205)
Run Code Online (Sandbox Code Playgroud)
我像这样实例化我的客户端.
return Feign.builder()
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder())
.logger(new Slf4jLogger())
.logLevel(Logger.Level.FULL)
.target(RegularFeignClient.class, url);
Run Code Online (Sandbox Code Playgroud) 如果我只是将 Hystrix 命令定义为类,我可以控制定义组键和命令键,如下所示。
private static class MyHystrixCommand extends HystrixCommand<MyResponseDto> {
public MyHystrixCommand() {
super(HystrixCommandGroupKey.Factory.asKey("MyHystrixGroup"));
}
Run Code Online (Sandbox Code Playgroud)
所以上面的代码组key是MyHystrixGroup,Command Key是MyHystrixCommand。
如果我想设置这个 hystrix 命令的任何配置,我可以这样做
ConfigurationManager.getConfigInstance().setProperty(
"hystrix.command.MyHystrixCommand.execution.timeout.enabled", false);
Run Code Online (Sandbox Code Playgroud)
默认情况下,
ConfigurationManager.getConfigInstance().setProperty(
"hystrix.command.default.execution.timeout.enabled", false);
Run Code Online (Sandbox Code Playgroud)
现在,当我使用 Feign Hystrix 时,我没有定义命令名称/组名称。根据此处的文档,组键与目标名称匹配,命令键与日志键相同。
所以如果我有一个这样的 FeignClient,
interface TestInterface {
@RequestLine("POST /")
String invoke() throws Exception;
}
Run Code Online (Sandbox Code Playgroud)
我在工厂类中创建了我的 Feign 客户端的实例。
class TestFactory {
public TestInterface newInstance() {
ConfigurationManager.getConfigInstance()
.setProperty("hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds", 500);
return HystrixFeign.builder()
.target(TestInterface.class, "http://localhost:" + server.getPort(), (FallbackFactory) new FallbackApiRetro());
}
}
Run Code Online (Sandbox Code Playgroud)
正如你在返回客户端之前看到的,我想设置我的 hystrix 命令的超时配置。
我正在用 MockWebServer 测试它。
@Test
public void fallbackFactory_example_timeout_fail() throws …Run Code Online (Sandbox Code Playgroud) 我有一个外部 csv 文件,其中包含要插入的数据。我的一列是数据类型时间戳(但它是一个可以为空的列)。数据值为 NULL/null 最终会出现以下异常。
Caused by: liquibase.exception.DatabaseException:
org.h2.jdbc.JdbcBatchUpdateException: Cannot parse "TIMESTAMP" constant ; SQL statement:
Run Code Online (Sandbox Code Playgroud)
我调试以查看生成的插入语句,当我进入 JdbcPreparedStatement 类时,CommandInterface 似乎具有空的 "" 字符串值而不是 NULL。
编辑: 偶然地,我试图在我的 liquibase 脚本中设置列的数据类型(可以有 NULL)并解决了这个问题。