Fix method annotation compile failed in native (#13490)
Signed-off-by: crazyhzm <crazyhzm@gmail.com>
This commit is contained in:
parent
0c766ad462
commit
c8f7269e41
|
|
@ -27,6 +27,7 @@ import org.apache.dubbo.common.utils.Assert;
|
|||
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;
|
||||
|
|
@ -758,6 +759,16 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
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<>();
|
||||
|
|
|
|||
|
|
@ -217,9 +217,8 @@ public class MethodConfig extends AbstractMethodConfig {
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
|||
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;
|
||||
|
|
@ -486,7 +487,13 @@ public class ServiceAnnotationPostProcessor
|
|||
// 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
|
||||
|
|
|
|||
Loading…
Reference in New Issue