Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix method annotation compile failed in native #13490

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading