Fix attributes is not passed by BeanDefinition (#13464)
* Fix attributes is not passed by BeanDefinition Signed-off-by: crazyhzm <crazyhzm@gmail.com> * Fix attributes in native Signed-off-by: crazyhzm <crazyhzm@gmail.com> --------- Signed-off-by: crazyhzm <crazyhzm@gmail.com>
This commit is contained in:
parent
c8f7269e41
commit
8f7446c81d
|
|
@ -759,6 +759,10 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
this.methods = (methods != null) ? new ArrayList<>(methods) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* It is only used in native scenarios to get methodConfigs.
|
||||
* @param methodsJson
|
||||
*/
|
||||
public void setMethodsJson(List<String> methodsJson) {
|
||||
if (methodsJson != null) {
|
||||
this.methods = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
|||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.utils.Assert;
|
||||
import org.apache.dubbo.common.utils.ClassUtils;
|
||||
import org.apache.dubbo.common.utils.JsonUtils;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.config.ReferenceConfig;
|
||||
import org.apache.dubbo.config.spring.aot.AotWithSpringDetector;
|
||||
|
|
@ -468,4 +469,15 @@ public class ReferenceBean<T>
|
|||
public void setInterfaceName(String interfaceName) {
|
||||
this.interfaceName = interfaceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* It is only used in native scenarios to get referenceProps
|
||||
* because attribute is not passed by BeanDefinition by default.
|
||||
* @param referencePropsJson
|
||||
*/
|
||||
public void setReferencePropsJson(String referencePropsJson) {
|
||||
if (StringUtils.isNotEmpty(referencePropsJson)) {
|
||||
this.referenceProps = JsonUtils.toJavaObject(referencePropsJson, Map.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,13 @@ import org.apache.dubbo.common.logger.LoggerFactory;
|
|||
import org.apache.dubbo.common.utils.ArrayUtils;
|
||||
import org.apache.dubbo.common.utils.Assert;
|
||||
import org.apache.dubbo.common.utils.ClassUtils;
|
||||
import org.apache.dubbo.common.utils.JsonUtils;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.apache.dubbo.config.spring.Constants;
|
||||
import org.apache.dubbo.config.spring.ReferenceBean;
|
||||
import org.apache.dubbo.config.spring.aot.AotWithSpringDetector;
|
||||
import org.apache.dubbo.config.spring.context.event.DubboConfigInitEvent;
|
||||
import org.apache.dubbo.config.spring.reference.ReferenceAttributes;
|
||||
import org.apache.dubbo.config.spring.reference.ReferenceBeanManager;
|
||||
|
|
@ -545,6 +547,9 @@ public class ReferenceAnnotationBeanPostProcessor extends AbstractAnnotationBean
|
|||
beanDefinition.getPropertyValues().add(ReferenceAttributes.INTERFACE_CLASS, interfaceClass);
|
||||
beanDefinition.getPropertyValues().add(ReferenceAttributes.INTERFACE_NAME, interfaceName);
|
||||
|
||||
if (AotWithSpringDetector.isAotProcessing()) {
|
||||
beanDefinition.getPropertyValues().add("referencePropsJson", JsonUtils.toJson(attributes));
|
||||
}
|
||||
// create decorated definition for reference bean, Avoid being instantiated when getting the beanType of
|
||||
// ReferenceBean
|
||||
// see org.springframework.beans.factory.support.AbstractBeanFactory#getTypeForFactoryBean()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import org.apache.dubbo.common.utils.StringUtils;
|
|||
import org.apache.dubbo.config.annotation.ProvidedBy;
|
||||
import org.apache.dubbo.config.spring.Constants;
|
||||
import org.apache.dubbo.config.spring.ReferenceBean;
|
||||
import org.apache.dubbo.config.spring.aot.AotWithSpringDetector;
|
||||
import org.apache.dubbo.config.spring.util.AnnotationUtils;
|
||||
import org.apache.dubbo.config.spring.util.DubboAnnotationUtils;
|
||||
import org.apache.dubbo.rpc.service.GenericService;
|
||||
|
|
@ -134,12 +133,7 @@ public class ReferenceBeanSupport {
|
|||
|
||||
public static String generateReferenceKey(Map<String, Object> attributes, ApplicationContext applicationContext) {
|
||||
|
||||
String interfaceClass;
|
||||
if (AotWithSpringDetector.useGeneratedArtifacts()) {
|
||||
interfaceClass = (String) attributes.get(ReferenceAttributes.INTERFACE_NAME);
|
||||
} else {
|
||||
interfaceClass = (String) attributes.get(ReferenceAttributes.INTERFACE);
|
||||
}
|
||||
String interfaceClass = (String) attributes.get(ReferenceAttributes.INTERFACE);
|
||||
Assert.notEmptyString(interfaceClass, "No interface class or name found from attributes");
|
||||
String group = (String) attributes.get(ReferenceAttributes.GROUP);
|
||||
String version = (String) attributes.get(ReferenceAttributes.VERSION);
|
||||
|
|
|
|||
Loading…
Reference in New Issue