Skip to content

Commit

Permalink
make multiple reference to service effect(apache#4674)
Browse files Browse the repository at this point in the history
  • Loading branch information
tswstarplanet committed Aug 1, 2019
1 parent 1173b40 commit 10cf5a8
Showing 1 changed file with 12 additions and 7 deletions.
Expand Up @@ -123,15 +123,15 @@ public Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> getInjectedMetho
protected Object doGetInjectedBean(AnnotationAttributes attributes, Object bean, String beanName, Class<?> injectedType,
InjectionMetadata.InjectedElement injectedElement) throws Exception {

String referencedBeanName = buildReferencedBeanName(attributes, injectedType);
String referencedBeanCacheKey = buildReferenceBeanCacheKey(attributes, injectedType);

ReferenceBean referenceBean = buildReferenceBeanIfAbsent(referencedBeanName, attributes, injectedType);
ReferenceBean referenceBean = buildReferenceBeanIfAbsent(referencedBeanCacheKey, attributes, injectedType);

registerReferenceBean(referencedBeanName, referenceBean, attributes, injectedType);
registerReferenceBean(referencedBeanCacheKey, referenceBean, attributes, injectedType);

cacheInjectedReferenceBean(referenceBean, injectedElement);

return buildProxy(referencedBeanName, referenceBean, injectedType);
return buildProxy(referencedBeanCacheKey, referenceBean, injectedType);
}

/**
Expand Down Expand Up @@ -279,25 +279,30 @@ protected String buildInjectedObjectCacheKey(AnnotationAttributes attributes, Ob
"#attributes=" + AnnotationUtils.resolvePlaceholders(attributes, getEnvironment());
}

private String buildReferenceBeanCacheKey(AnnotationAttributes attributes, Class<?> injectedType) {
return buildReferencedBeanName(attributes, injectedType) +
"#attributes=" + AnnotationUtils.resolvePlaceholders(attributes, getEnvironment());
}

private String buildReferencedBeanName(AnnotationAttributes attributes, Class<?> injectedType) {

ServiceBeanNameBuilder serviceBeanNameBuilder = create(attributes, injectedType, getEnvironment());

return serviceBeanNameBuilder.build();
}

private ReferenceBean buildReferenceBeanIfAbsent(String referencedBeanName, AnnotationAttributes attributes,
private ReferenceBean buildReferenceBeanIfAbsent(String referencedBeanCacheKey, AnnotationAttributes attributes,
Class<?> referencedType)
throws Exception {

ReferenceBean<?> referenceBean = referenceBeanCache.get(referencedBeanName);
ReferenceBean<?> referenceBean = referenceBeanCache.get(referencedBeanCacheKey);

if (referenceBean == null) {
ReferenceBeanBuilder beanBuilder = ReferenceBeanBuilder
.create(attributes, applicationContext)
.interfaceClass(referencedType);
referenceBean = beanBuilder.build();
referenceBeanCache.put(referencedBeanName, referenceBean);
referenceBeanCache.put(referencedBeanCacheKey, referenceBean);
}

return referenceBean;
Expand Down

0 comments on commit 10cf5a8

Please sign in to comment.