Skip to content

Commit

Permalink
Fix method annotation compile failed 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 0c766ad commit 5016a3f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.support.Parameter;
Expand Down Expand Up @@ -758,6 +759,16 @@ public void setMethods(List<? extends MethodConfig> methods) {
this.methods = (methods != null) ? new ArrayList<>(methods) : null;
}

public void setMethodsJson(List<String> methodsJson) {
if (methodsJson != null) {
this.methods = new ArrayList<>();
methodsJson.forEach(
(methodConfigJson) -> methods.add(JsonUtils.toJavaObject(methodConfigJson, MethodConfig.class)));
} else {
this.methods = null;
}
}

public void addMethod(MethodConfig methodConfig) {
if (this.methods == null) {
this.methods = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,8 @@ public List<String> getPrefixes() {
List<String> prefixes = new ArrayList<>();
prefixes.add(parentPrefix + "." + this.getName());
return prefixes;
} else {
throw new IllegalStateException("The parent prefix of MethodConfig is null");
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public abstract class AotWithSpringDetector {
*/
public static final String AOT_ENABLED = "spring.aot.enabled";

private static final String AOT_PROCESSING = "spring.aot.processing";

/**
* Determine whether AOT optimizations must be considered at runtime. This
* is mandatory in a native image but can be triggered on the JVM using
Expand All @@ -40,4 +42,8 @@ public abstract class AotWithSpringDetector {
public static boolean useGeneratedArtifacts() {
return (NativeDetector.inNativeImage() || SpringProperties.getFlag(AOT_ENABLED));
}

public static boolean isAotProcessing() {
return (NativeDetector.inNativeImage() || SpringProperties.getFlag(AOT_PROCESSING));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.AnnotationUtils;
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.Constants;
Expand Down Expand Up @@ -486,7 +487,13 @@ private AbstractBeanDefinition buildServiceBeanDefinition(
// Add methods parameters
List<MethodConfig> methodConfigs = convertMethodConfigs(serviceAnnotationAttributes.get("methods"));
if (!methodConfigs.isEmpty()) {
builder.addPropertyValue("methods", methodConfigs);
if (AotWithSpringDetector.isAotProcessing()) {
List<String> methodsJson = new ArrayList<>();
methodConfigs.forEach(methodConfig -> methodsJson.add(JsonUtils.toJson(methodConfig)));
builder.addPropertyValue("methodsJson", methodsJson);
} else {
builder.addPropertyValue("methods", methodConfigs);
}
}

// convert provider to providerIds
Expand Down

0 comments on commit 5016a3f

Please sign in to comment.