Mar*_*rco 3 spring spring-boot spring-boot-actuator
我正在使用以下类实现自定义端点:
@Component
@Endpoint(id = "bootstrap")
public class BootstrapUrlEndpoint {
private final URL bootstrapUrl;
@Autowired
public BootstrapUrlEndpoint(URL bootstrapUrl) {
this.bootstrapUrl = bootstrapUrl;
}
@ReadOperation
public Map<String, String> getBootstrapUrl() {
Map<String, String> result = new HashMap<>();
result.put("bootstrap_url", bootstrapUrl.toExternalForm());
return result;
}
@WriteOperation
public void setBootstrapUrl(@Selector String property, String value) throws MalformedURLException {
System.out.println(String.format(">>> Setting %s = %s", property, value));
}
}
Run Code Online (Sandbox Code Playgroud)
这一切都"按预期工作" 没有的@Selector注释; 忽略它,并发送POST至http://localhost:8080/actuator/bootstrap具有:
{
"value": "http://localhost:27017/tables/application"
}
Run Code Online (Sandbox Code Playgroud)
按预期调用方法.
但是,我无法使"选择器"工作; 我在启动日志中看到它被注册为有效端点:
Mapped "{[/actuator/bootstrap/{arg0}],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public org.reactivestreams....ava.util.Map<java.lang.String, java.lang.String>)
Run Code Online (Sandbox Code Playgroud)
不幸的是,使用POST /actuator/bootstrap/myprop和相同的主体调用它会产生一个400 Bad Request没有错误日志或错误消息.
我一直在寻找更多的信息和可能的例子:我能找到的唯一相关(但是,唉,不完整)的例子就是这篇文章 - 有人会知道我的代码中缺少什么吗?
提前致谢!
顺便说一下,我遇到了和你一样的问题而且有点疯狂.
但我发现问题与注释的参数的参数命名有关@Selector.
如果您将var"property"命名为"arg0",则所有这些都将起作用:
public void setBootstrapUrl(@Selector String arg0, String value)
Run Code Online (Sandbox Code Playgroud)
是的,我知道这有点奇怪但我在本文中发现了一些关于编译类时嵌入参数的信息.
我仍然没有在参数中使用我自己的名字.
| 归档时间: |
|
| 查看次数: |
1691 次 |
| 最近记录: |