如何解决Micronaut:实现自定义信息端点元素
我正在尝试实现由 Micronaut's Info Endpoint 发布的自定义元素,但在查询 /info
时没有出现自定义数据。使用 Micronaut 2.4.0 版。
这是我目前的代码:
application.yml
[...]
endpoints:
info:
enabled: true
sensitive: false
git:
enabled: true
[...]
build.gradle
dependencies {
[...]
implementation('io.micronaut:micronaut-management')
[...]
}
RegisteredUsersInfo
import io.micronaut.context.env.MapPropertySource;
import io.micronaut.context.env.PropertySource;
import io.micronaut.management.endpoint.info.InfoSource;
import io.micronaut.runtime.context.scope.Refreshable;
import org.reactivestreams.Publisher;
import java.util.Map;
import java.util.Set;
import static io.reactivex.Flowable.just;
//@Singleton // No success even with this annotation set
public class RegisteredUsersInfo implements InfoSource {
// Business component to receive data from:
private final SubjectMetadataDataSource subjectMetadataDataSource;
public RegisteredUsersInfo(final SubjectMetadataDataSource subjectMetadataDataSource) {
this.subjectMetadataDataSource = subjectMetadataDataSource;
}
@Override
public Publisher<PropertySource> getSource() {
return just(getUserPropertySource());
}
private PropertySource getUserPropertySource() {
final Map<String,Set<String>> userProperties =
Map.of("knownID",subjectMetadataDataSource.listOfKnownUserIDs());
return new MapPropertySource("user",userProperties);
}
}
我看不出这有什么遗漏/错误。任何帮助表示赞赏。
背景信息:提到的 Git Info Source 按预期工作。
谢谢
基督徒
解决方法
好的,对方法 getUserPropertySource()
稍作改动:
[...]
final Map<String,Set<String>> userProperties =
Map.of("knownID",Set.of("foo","bar","baz"));
[...]
在查询 /info
时给我以下响应:
{
"known-id": [
"foo","baz","bar"
],[...]
}
所以我的“问题”的原因是 subjectMetadataDataSource.listOfKnownUserIDs()
返回一个空的 Set
!
应用
[...]
final Map<String,Set.of());
[...]
从 /info
响应中重现预期的额外 JSON 元素的消失。
我希望得到一个空输入的空 JSON 数组,如下所示:
{
"known-id": [],[...]
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。