diff --git a/samples/springboot-samples/pom.xml b/samples/springboot-samples/pom.xml index fef2afc13..60086128c 100644 --- a/samples/springboot-samples/pom.xml +++ b/samples/springboot-samples/pom.xml @@ -21,7 +21,7 @@ 2.7.16 1.8 2.2.7 - 0.5.6 + 0.5.7-SNAPSHOT 3.4.2 1.7.1 0.6.1 diff --git a/samples/springboot-samples/service/base/base-bootstrap/src/main/java/com/alipay/sofa/base/BaseApplication.java b/samples/springboot-samples/service/base/base-bootstrap/src/main/java/com/alipay/sofa/base/BaseApplication.java index 18b6579a9..975721ad8 100644 --- a/samples/springboot-samples/service/base/base-bootstrap/src/main/java/com/alipay/sofa/base/BaseApplication.java +++ b/samples/springboot-samples/service/base/base-bootstrap/src/main/java/com/alipay/sofa/base/BaseApplication.java @@ -8,6 +8,8 @@ public class BaseApplication { public static void main(String[] args) { + System.setProperty("spring.service.delay.addressing.enable", "true"); + SpringApplication.run(BaseApplication.class, args); System.out.println("SofaArkSpringGuidesApplication start!"); System.out.println("Spring Boot Version: " + SpringApplication.class.getPackage().getImplementationVersion()); diff --git a/samples/springboot-samples/service/base/base-bootstrap/src/main/java/com/alipay/sofa/base/rest/SampleController.java b/samples/springboot-samples/service/base/base-bootstrap/src/main/java/com/alipay/sofa/base/rest/SampleController.java index 6b24246ca..15f43f4c7 100644 --- a/samples/springboot-samples/service/base/base-bootstrap/src/main/java/com/alipay/sofa/base/rest/SampleController.java +++ b/samples/springboot-samples/service/base/base-bootstrap/src/main/java/com/alipay/sofa/base/rest/SampleController.java @@ -3,11 +3,13 @@ import com.alipay.sofa.biz.facade.Param; import com.alipay.sofa.biz.facade.Provider; import com.alipay.sofa.biz.facade.Result; +import com.alipay.sofa.serverless.common.api.AutowiredFromBiz; import com.alipay.sofa.serverless.common.api.SpringServiceFinder; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import java.util.List; import java.util.Map; /** @@ -19,9 +21,28 @@ @RestController public class SampleController { + @AutowiredFromBiz(bizName = "biz1", bizVersion = "0.0.1-SNAPSHOT", name = "studentProvider") + private Provider studentProvider; + + @AutowiredFromBiz(bizName = "biz1", name = "teacherProvider") + private Provider teacherProvider; + @RequestMapping(value = "/", method = RequestMethod.GET) public String hello() { + Result tmp = studentProvider.provide(new Param()); + System.out.println(tmp.getClass()); + System.out.println(tmp.isSuccess()); + System.out.println(tmp.getPeople().getClass()); + System.out.println(tmp); + + Result tmp1 = teacherProvider.provide(new Param()); + System.out.println(tmp1.getClass()); + System.out.println(tmp1.isSuccess()); + System.out.println(tmp1.getPeople().getClass()); + System.out.println(tmp1); + + Provider studentProvider = SpringServiceFinder.getModuleService("biz1", "0.0.1-SNAPSHOT", "studentProvider", Provider.class); Result result = studentProvider.provide(new Param()); diff --git a/sofa-serverless-runtime/sofa-serverless-base-plugin/src/main/java/com/alipay/sofa/serverless/plugin/BaseRuntimeAutoConfiguration.java b/sofa-serverless-runtime/sofa-serverless-base-plugin/src/main/java/com/alipay/sofa/serverless/plugin/BaseRuntimeAutoConfiguration.java index 4a5f5e761..d6b29564e 100644 --- a/sofa-serverless-runtime/sofa-serverless-base-plugin/src/main/java/com/alipay/sofa/serverless/plugin/BaseRuntimeAutoConfiguration.java +++ b/sofa-serverless-runtime/sofa-serverless-base-plugin/src/main/java/com/alipay/sofa/serverless/plugin/BaseRuntimeAutoConfiguration.java @@ -43,7 +43,7 @@ public BizRuntimeContext bizRuntimeContext(ApplicationContext applicationContext @Bean @ConditionalOnMissingBean - @ConditionalOnNotMasterBiz + // @ConditionalOnNotMasterBiz public ArkAutowiredBeanPostProcessor arkAutowiredBeanPostProcessor() { return new ArkAutowiredBeanPostProcessor(); } diff --git a/sofa-serverless-runtime/sofa-serverless-base-plugin/src/test/java/com/alipay/sofa/serverless/plugin/BaseRuntimeAutoConfigurationTest.java b/sofa-serverless-runtime/sofa-serverless-base-plugin/src/test/java/com/alipay/sofa/serverless/plugin/BaseRuntimeAutoConfigurationTest.java index 3a5ebf778..c9077d497 100644 --- a/sofa-serverless-runtime/sofa-serverless-base-plugin/src/test/java/com/alipay/sofa/serverless/plugin/BaseRuntimeAutoConfigurationTest.java +++ b/sofa-serverless-runtime/sofa-serverless-base-plugin/src/test/java/com/alipay/sofa/serverless/plugin/BaseRuntimeAutoConfigurationTest.java @@ -51,7 +51,7 @@ public void prepare() { public void test() { contextRunner.run(context -> { Assertions.assertThat(context).hasSingleBean(BizRuntimeContext.class); - Assertions.assertThat(context).doesNotHaveBean(ArkAutowiredBeanPostProcessor.class); + Assertions.assertThat(context).hasSingleBean(ArkAutowiredBeanPostProcessor.class); }); } } diff --git a/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/api/SpringServiceFinder.java b/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/api/SpringServiceFinder.java index 85b05aae9..4edfab62f 100644 --- a/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/api/SpringServiceFinder.java +++ b/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/api/SpringServiceFinder.java @@ -22,8 +22,6 @@ import java.util.Map; -import static com.alipay.sofa.serverless.common.service.ServiceProxyFactory.determineMostSuitableBiz; - /** * @author: yuanyuan * @date: 2023/9/21 9:11 下午 @@ -32,35 +30,38 @@ public class SpringServiceFinder { public static T getBaseService(String name, Class serviceType) { Biz masterBiz = ArkClient.getMasterBiz(); - return ServiceProxyFactory.createServiceProxy(masterBiz, name, serviceType, null); + return ServiceProxyFactory.createServiceProxy(masterBiz.getBizName(), + masterBiz.getBizVersion(), name, serviceType, null); } public static T getBaseService(Class serviceType) { Biz masterBiz = ArkClient.getMasterBiz(); - return ServiceProxyFactory.createServiceProxy(masterBiz, serviceType, null); + return ServiceProxyFactory.createServiceProxy(masterBiz.getBizName(), + masterBiz.getBizVersion(), null, serviceType, null); } public static Map listBaseServices(Class serviceType) { Biz masterBiz = ArkClient.getMasterBiz(); - return ServiceProxyFactory.batchCreateServiceProxy(masterBiz, serviceType, null); + return ServiceProxyFactory.batchCreateServiceProxy(masterBiz.getBizName(), + masterBiz.getBizVersion(), serviceType, null); } public static T getModuleService(String moduleName, String moduleVersion, String name, Class serviceType) { - Biz biz = determineMostSuitableBiz(moduleName, moduleVersion); - return ServiceProxyFactory.createServiceProxy(biz, name, serviceType, null); + return ServiceProxyFactory.createServiceProxy(moduleName, moduleVersion, name, serviceType, + null); } public static T getModuleService(String moduleName, String moduleVersion, Class serviceType) { - Biz biz = determineMostSuitableBiz(moduleName, moduleVersion); - return ServiceProxyFactory.createServiceProxy(biz, serviceType, null); + return ServiceProxyFactory.createServiceProxy(moduleName, moduleVersion, null, serviceType, + null); } public static Map listModuleServices(String moduleName, String moduleVersion, Class serviceType) { - Biz biz = determineMostSuitableBiz(moduleName, moduleVersion); - return ServiceProxyFactory.batchCreateServiceProxy(biz, serviceType, null); + return ServiceProxyFactory.batchCreateServiceProxy(moduleName, moduleVersion, serviceType, + null); } } diff --git a/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/service/ArkAutowiredBeanPostProcessor.java b/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/service/ArkAutowiredBeanPostProcessor.java index af40c503e..e38a3ebb4 100644 --- a/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/service/ArkAutowiredBeanPostProcessor.java +++ b/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/service/ArkAutowiredBeanPostProcessor.java @@ -38,8 +38,6 @@ import java.util.Map; import java.util.Set; -import static com.alipay.sofa.serverless.common.service.ServiceProxyFactory.determineMostSuitableBiz; - /** * @author: yuanyuan * @date: 2023/9/26 11:29 上午 @@ -59,15 +57,19 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro AutowiredFromBase autowiredFromBase = field.getAnnotation(AutowiredFromBase.class); AutowiredFromBiz autowiredFromBiz = field.getAnnotation(AutowiredFromBiz.class); - Biz biz; + String bizName; + String bizVersion; String name; boolean required; if (autowiredFromBase != null) { - biz = ArkClient.getMasterBiz(); + Biz masterBiz = ArkClient.getMasterBiz(); + bizName = masterBiz.getBizName(); + bizVersion = masterBiz.getBizVersion(); name = autowiredFromBase.name(); required = autowiredFromBase.required(); } else if (autowiredFromBiz != null) { - biz = determineMostSuitableBiz(autowiredFromBiz.bizName(), autowiredFromBiz.bizVersion()); + bizName = autowiredFromBiz.bizName(); + bizVersion = autowiredFromBiz.bizVersion(); name = autowiredFromBiz.name(); required = autowiredFromBiz.required(); } else { @@ -80,12 +82,12 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro try { Class fieldType = field.getType(); if (StringUtils.hasText(name)) { - serviceProxy = ServiceProxyFactory.createServiceProxy(biz, name, fieldType, clientClassLoader); + serviceProxy = ServiceProxyFactory.createServiceProxy(bizName, bizVersion, name, fieldType, clientClassLoader); } if (serviceProxy == null) { if (!Collection.class.isAssignableFrom(fieldType) && !Map.class.isAssignableFrom(fieldType)) { - serviceProxy = ServiceProxyFactory.createServiceProxy(biz, fieldType, clientClassLoader); + serviceProxy = ServiceProxyFactory.createServiceProxy(bizName, bizVersion, null, fieldType, clientClassLoader); } } @@ -98,7 +100,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro serviceType = (Class) actualTypeArguments[1]; } - Map serviceProxyMap = ServiceProxyFactory.batchCreateServiceProxy(biz, serviceType, clientClassLoader); + Map serviceProxyMap = ServiceProxyFactory.batchCreateServiceProxy(bizName, bizVersion, serviceType, clientClassLoader); if (Map.class.isAssignableFrom(fieldType)) { serviceProxy = serviceProxyMap; @@ -126,7 +128,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro if (serviceProxy != null) { ReflectionUtils.makeAccessible(field); ReflectionUtils.setField(field, bean, serviceProxy); - LOGGER.info("Finished processing bean [{}], injected object [{}] to bean [{}] field [{}]", beanName, serviceProxy, bean, field); + LOGGER.info("Finished processing bean [{}], success to inject object to bean [{}] field [{}]", beanName, bean, field); } }, field -> !Modifier.isStatic(field.getModifiers()) diff --git a/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/service/ServiceProxyFactory.java b/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/service/ServiceProxyFactory.java index f317390d1..358216863 100644 --- a/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/service/ServiceProxyFactory.java +++ b/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/service/ServiceProxyFactory.java @@ -17,7 +17,6 @@ package com.alipay.sofa.serverless.common.service; import com.alipay.sofa.ark.api.ArkClient; -import com.alipay.sofa.ark.common.util.StringUtils; import com.alipay.sofa.ark.spi.model.Biz; import com.alipay.sofa.ark.spi.model.BizState; import com.alipay.sofa.serverless.common.BizRuntimeContext; @@ -28,6 +27,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.util.StringUtils; import java.util.HashMap; import java.util.List; @@ -45,42 +45,68 @@ */ public class ServiceProxyFactory { - public static T createServiceProxy(Biz biz, String name, Class serviceType, - ClassLoader clientClassLoader) { - T service = getService(biz, name); - return doCreateServiceProxy(biz, service, serviceType, clientClassLoader); + public static T createServiceProxy(String bizName, String bizVersion, String name, + Class clientType, ClassLoader clientClassLoader) { + Object service = getService(bizName, bizVersion, name, clientType); + return doCreateServiceProxy(bizName, bizVersion, service, name, clientType, + clientClassLoader); } - public static T createServiceProxy(Biz biz, Class serviceType, - ClassLoader clientClassLoader) { - Class serviceClass = checkBizStateAndGetTargetClass(biz, serviceType); - T service = (T) getService(biz, serviceClass); - return doCreateServiceProxy(biz, service, serviceType, clientClassLoader); - } - - public static Map batchCreateServiceProxy(Biz biz, Class serviceType, + public static Map batchCreateServiceProxy(String bizName, String bizVersion, + Class serviceType, ClassLoader clientClassLoader) { + Biz biz = ArkClient.getBizManagerService().getBiz(bizName, bizVersion); Class serviceClass = checkBizStateAndGetTargetClass(biz, serviceType); Map serviceMap = listService(biz, serviceClass); Map proxyMap = new HashMap<>(); for (String beanName : serviceMap.keySet()) { - proxyMap - .put( - beanName, - doCreateServiceProxy(biz, serviceMap.get(beanName), serviceType, - clientClassLoader)); + proxyMap.put( + beanName, + doCreateServiceProxy(biz.getBizName(), biz.getBizVersion(), + serviceMap.get(beanName), null, serviceType, clientClassLoader)); } return proxyMap; } - private static T getService(Biz biz, String name) { - BizRuntimeContext bizRuntimeContext = checkBizStateAndGetBizRuntimeContext(biz); - return (T) bizRuntimeContext.getRootApplicationContext().getBean(name); - } + public static Object getService(String bizName, String bizVersion, String name, + Class clientType) { + Biz biz = determineMostSuitableBiz(bizName, bizVersion); - private static T getService(Biz biz, Class serviceType) { - BizRuntimeContext bizRuntimeContext = checkBizStateAndGetBizRuntimeContext(biz); - return bizRuntimeContext.getRootApplicationContext().getBean(serviceType); + if (biz == null && Boolean.getBoolean("spring.service.delay.addressing.enable")) { + return null; + } + + if (biz == null) { + throw new BizRuntimeException(E100003, "biz does not exist"); + } else if (biz.getBizState() != BizState.ACTIVATED + && biz.getBizState() != BizState.DEACTIVATED) { + throw new BizRuntimeException(E100004, "biz state is not valid"); + } + + BizRuntimeContext bizRuntimeContext = BizRuntimeContextRegistry.getBizRuntimeContext(biz); + if (bizRuntimeContext == null) { + throw new BizRuntimeException(E100002, "biz runtime context is null"); + } + if (bizRuntimeContext.getRootApplicationContext() == null) { + throw new BizRuntimeException(E100002, "biz spring context is null"); + } + + if (StringUtils.hasText(name)) { + return bizRuntimeContext.getRootApplicationContext().getBean(name); + } + + if (clientType != null) { + Class serviceType; + try { + serviceType = biz.getBizClassLoader().loadClass(clientType.getName()); + } catch (ClassNotFoundException e) { + throw new BizRuntimeException(E100005, "Cannot find class " + clientType.getName() + + " from the biz " + biz.getIdentity()); + } + return bizRuntimeContext.getRootApplicationContext().getBean(serviceType); + } + + throw new BizRuntimeException(E100002, "invalid config"); } private static Map listService(Biz biz, Class serviceType) { @@ -96,41 +122,49 @@ private static Map listService(Biz biz, Class serviceType) { /** * @param biz 目标biz + * @param name 目标biz中beanName * @param service 目标biz中符合条件的bean - * @param serviceType 调用方serviceType + * @param clientType 调用方clientType * @param clientClassLoader 调用方classloader * @return 供调用方调用的代理对象 */ - private static T doCreateServiceProxy(Biz biz, Object service, Class serviceType, ClassLoader clientClassLoader) { + private static T doCreateServiceProxy(String bizName, String bizVersion, Object service, String name, Class clientType, ClassLoader clientClassLoader) { if (clientClassLoader == null) { Class callerClass = ReflectionUtils.getCallerClass(6); clientClassLoader = callerClass.getClassLoader(); } BizRuntimeContext bizRuntimeContext = BizRuntimeContextRegistry.getBizRuntimeContextByClassLoader(clientClassLoader); - Map> serviceProxyCaches = - bizRuntimeContext.getServiceProxyCaches(); - Map cacheMap = serviceProxyCaches.computeIfAbsent(biz.getBizClassLoader(), o -> new ConcurrentHashMap<>()); - // 服务端模块被卸载时,cacheMap会被清空,需要重新生成proxy并缓存 - if (cacheMap.containsKey(service.getClass().getName())) { - ServiceProxyCache serviceProxyCache = cacheMap.get(service.getClass().getName()); - return (T) serviceProxyCache.getProxy(); - } - - SpringServiceInvoker serviceInvoker = new SpringServiceInvoker(service, biz.getBizName(), - biz.getBizVersion(), biz.getIdentity(), clientClassLoader, service - .getClass().getClassLoader()); + Map> serviceProxyCaches = bizRuntimeContext.getServiceProxyCaches(); + + Biz biz = determineMostSuitableBiz(bizName, bizVersion); + + if (biz != null) { + Map cacheMap = serviceProxyCaches.computeIfAbsent(biz.getBizClassLoader(), o -> new ConcurrentHashMap<>()); + // 服务端模块被卸载时,cacheMap会被清空,需要重新生成proxy并缓存 + String cacheKey = service != null ? service.getClass().getName() : clientType.getName(); + if (cacheMap.containsKey(cacheKey)) { + ServiceProxyCache serviceProxyCache = cacheMap.get(cacheKey); + return (T) serviceProxyCache.getProxy(); + } + } + + SpringServiceInvoker serviceInvoker = new SpringServiceInvoker(service, name, clientType, bizName, bizVersion, clientClassLoader, service != null ? service.getClass().getClassLoader() : null); ProxyFactory factory = new ProxyFactory(); - if (serviceType.isInterface()) { - factory.addInterface(serviceType); + if (clientType.isInterface()) { + factory.addInterface(clientType); } else { - factory.setTargetClass(serviceType); + factory.setTargetClass(clientType); factory.setProxyTargetClass(true); } factory.addAdvice(serviceInvoker); Object proxy = factory.getProxy(clientClassLoader); - cacheMap.put(service.getClass().getName(), new ServiceProxyCache(proxy, serviceInvoker)); + if (biz != null) { + String cacheKey = service != null ? service.getClass().getName() : clientType.getName(); + Map cacheMap = serviceProxyCaches.computeIfAbsent(biz.getBizClassLoader(), o -> new ConcurrentHashMap<>()); + cacheMap.put(cacheKey, new ServiceProxyCache(proxy, serviceInvoker)); + } return (T) proxy; } @@ -139,6 +173,9 @@ public static Biz determineMostSuitableBiz(String moduleName, String moduleVersi Biz biz; if (StringUtils.isEmpty(moduleVersion)) { List bizList = ArkClient.getBizManagerService().getBiz(moduleName); + if (bizList.size() == 0) { + return null; + } biz = bizList.stream().filter(it -> BizState.ACTIVATED == it.getBizState()).findFirst().get(); } else { biz = ArkClient.getBizManagerService().getBiz(moduleName, moduleVersion); diff --git a/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/service/SpringServiceInvoker.java b/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/service/SpringServiceInvoker.java index 75e31507c..64e023079 100644 --- a/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/service/SpringServiceInvoker.java +++ b/sofa-serverless-runtime/sofa-serverless-common/src/main/java/com/alipay/sofa/serverless/common/service/SpringServiceInvoker.java @@ -16,7 +16,6 @@ */ package com.alipay.sofa.serverless.common.service; -import com.alipay.sofa.ark.api.ArkClient; import com.alipay.sofa.ark.spi.model.Biz; import com.alipay.sofa.ark.spi.model.BizState; import com.alipay.sofa.serverless.common.exception.BizRuntimeException; @@ -30,6 +29,8 @@ import static com.alipay.sofa.serverless.common.exception.ErrorCodes.SpringContextManager.E100003; import static com.alipay.sofa.serverless.common.exception.ErrorCodes.SpringContextManager.E100004; +import static com.alipay.sofa.serverless.common.service.ServiceProxyFactory.determineMostSuitableBiz; +import static com.alipay.sofa.serverless.common.service.ServiceProxyFactory.getService; import static com.alipay.sofa.serverless.common.util.SerializeUtils.serializeTransform; /** @@ -47,12 +48,14 @@ public class SpringServiceInvoker implements MethodInterceptor { private Object target; // 被调用方目标bean + private String name; + + private Class clientType; + private String bizName; // 被调用方bizName private String bizVersion; // 被调用方bizVersion - private String bizIdentity; // 被调用方bizIdentity - private ClassLoader clientClassLoader; // 调用方classloader private ClassLoader serviceClassLoader; // 被调用方classloader @@ -60,20 +63,22 @@ public class SpringServiceInvoker implements MethodInterceptor { public SpringServiceInvoker() { } - public SpringServiceInvoker(Object target, String bizName, String bizVersion, - String bizIdentity, ClassLoader clientClassLoader, + public SpringServiceInvoker(Object target, String name, Class clientType, String bizName, + String bizVersion, ClassLoader clientClassLoader, ClassLoader serviceClassLoader) { this.target = target; + this.name = name; + this.clientType = clientType; this.bizName = bizName; this.bizVersion = bizVersion; - this.bizIdentity = bizIdentity; this.clientClassLoader = clientClassLoader; this.serviceClassLoader = serviceClassLoader; } @Override public Object invoke(MethodInvocation invocation) throws Throwable { - Biz biz = ArkClient.getBizManagerService().getBiz(bizName, bizVersion); + // todo bizVersion = "" 时 + Biz biz = determineMostSuitableBiz(bizName, bizVersion); if (biz == null) { throw new BizRuntimeException(E100003, "biz does not exist when called"); } @@ -81,6 +86,16 @@ public Object invoke(MethodInvocation invocation) throws Throwable { throw new BizRuntimeException(E100004, "biz state is not valid"); } + // delayed addressing + if (this.target == null) { + this.target = getService(bizName, bizVersion, name, clientType); + if (this.target == null) { + throw new BizRuntimeException(E100004, "Cannot find service bean from the biz " + + biz.getIdentity()); + } + this.serviceClassLoader = this.target.getClass().getClassLoader(); + } + ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); long startTime = System.currentTimeMillis(); try { @@ -155,7 +170,7 @@ private Method getTargetMethod(Method method, Class[] argumentTypes) { try { return target.getClass().getMethod(method.getName(), argumentTypes); } catch (NoSuchMethodException ex) { - throw new IllegalStateException(target + " in " + bizIdentity + throw new IllegalStateException(target + " in " + bizName + ":" + bizVersion + " don't have the method " + method); } } diff --git a/sofa-serverless-runtime/sofa-serverless-common/src/test/java/com/alipay/sofa/serverless/common/SpringServiceAndBeanFinderTest.java b/sofa-serverless-runtime/sofa-serverless-common/src/test/java/com/alipay/sofa/serverless/common/SpringServiceAndBeanFinderTest.java index 353800694..ccc6b6090 100644 --- a/sofa-serverless-runtime/sofa-serverless-common/src/test/java/com/alipay/sofa/serverless/common/SpringServiceAndBeanFinderTest.java +++ b/sofa-serverless-runtime/sofa-serverless-common/src/test/java/com/alipay/sofa/serverless/common/SpringServiceAndBeanFinderTest.java @@ -136,7 +136,6 @@ public void testSpringServiceFinder() { Mockito.when(biz2.getBizState()).thenReturn(BizState.ACTIVATED); Mockito.when(biz2.getBizClassLoader()).thenReturn(loader); Mockito.when(biz2.getBizName()).thenReturn("biz2"); - Mockito.when(biz2.getBizVersion()).thenReturn("version1"); BizRuntimeContext biz2Runtime = new BizRuntimeContext(biz2, biz2Ctx); BizRuntimeContextRegistry.registerBizRuntimeManager(biz2Runtime); ModuleBean foundModuleBean = SpringServiceFinder.getModuleService("biz2", "version1",