我为一项服务构建了两个不同的服务连接器。如果我将两个服务连接器都添加到我的应用程序中,Spring 将不会开始说没有找到合适的服务连接器。我调试到 spring 中,发现只有一个连接器被添加到内部连接器列表中。是否可以为一项服务添加两个不同的 spring 云服务连接器并在一个应用程序中使用它们?
为了更好地理解 rabbitMQ 服务的示例。假设我使用 aCloudFoundryServiceInfoCreator<AMQConnectionInfo>
和 a构建了两个不同的云服务连接器CloudFoundryServiceInfoCreator<MQTTConnectionInfo>
。我想在应用程序中使用这两个连接器(我知道我可以在一个弹簧云连接器中实现这两个连接信息,但这不是我想做的)。
编辑:引发以下异常:
org.springframework.cloud.CloudException: No unique service matching class .... found. Expected 1, found 0
at org.springframework.cloud.Cloud.getSingletonServiceConnector(Cloud.java:149)
我也尝试使用cloud.getServiceConnector(id, class, null);
.
我还发现 Spring Cloud Connectors 只返回在此方法中找到的第一个连接器org.springframework.cloud.AbstractCloudConnector
:
private ServiceInfo getServiceInfo(SD serviceData) {
for (ServiceInfoCreator<? extends ServiceInfo,SD> serviceInfoCreator : serviceInfoCreators) {
if (serviceInfoCreator.accept(serviceData)) {
return serviceInfoCreator.createServiceInfo(serviceData);
}
}
// Fallback with a warning
ServiceInfo fallackServiceInfo = getFallbackServiceInfoCreator().createServiceInfo(serviceData);
logger.warning("No suitable service info creator found for service " + fallackServiceInfo.getId()
+ " Did you forget to add a ServiceInfoCreator?");
return fallackServiceInfo;
}
我认为如果这会返回一个合适的 ServiceInfoCreator 列表或搜索我请求的列表会很好,不是吗?