Skip to content

Commit

Permalink
Fix attributes in native
Browse files Browse the repository at this point in the history
Signed-off-by: crazyhzm <crazyhzm@gmail.com>
  • Loading branch information
CrazyHZM committed Dec 12, 2023
1 parent cc5c54e commit 8fc65ab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,10 @@ public void setMethods(List<? extends MethodConfig> methods) {
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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,6 @@ public ReferenceBean(Map<String, Object> referenceProps) {
this.referenceProps = referenceProps;
}

/**
* It is only used in native scenarios to get referenceProps
* because attribute is not passed by BeanDefinition by default.
* Passing a json string through a constructor is by far a simpler way.
* @param referencePropsJson
*/
public ReferenceBean(String referencePropsJson) {
if (StringUtils.isNotEmpty(referencePropsJson)) {
this.referenceProps = JsonUtils.toJavaObject(referencePropsJson, Map.class);
}
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
Expand Down Expand Up @@ -482,7 +470,14 @@ public void setInterfaceName(String interfaceName) {
this.interfaceName = interfaceName;
}

public void setReferenceProps(Map<String, Object> referenceProps) {
this.referenceProps = referenceProps;
/**
* 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -59,7 +60,6 @@
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.support.AbstractBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
Expand Down Expand Up @@ -547,9 +547,9 @@ public String registerReferenceBean(
beanDefinition.getPropertyValues().add(ReferenceAttributes.INTERFACE_CLASS, interfaceClass);
beanDefinition.getPropertyValues().add(ReferenceAttributes.INTERFACE_NAME, interfaceName);

ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
constructorArgumentValues.addIndexedArgumentValue(0, JsonUtils.toJson(attributes));
beanDefinition.setConstructorArgumentValues(constructorArgumentValues);
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()
Expand Down

0 comments on commit 8fc65ab

Please sign in to comment.