diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java index 9dd8cf92e..d5c6ff90f 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java @@ -167,7 +167,7 @@ private ComponentInfo doRegister(ComponentInfo ci) { ci.register(); } catch (Throwable t) { SofaLogger.error(ErrorCode.convert("01-03003", ci.getName()), t); - return null; + throw new ServiceRuntimeException(ErrorCode.convert("01-03003", ci.getName())); } SofaLogger.info("Registering component: {}", ci.getName()); @@ -189,6 +189,7 @@ private ComponentInfo doRegister(ComponentInfo ci) { } catch (Throwable t) { ci.exception(new Exception(t)); SofaLogger.error(ErrorCode.convert("01-03004", ci.getName()), t); + throw new ServiceRuntimeException(ErrorCode.convert("01-03004", ci.getName())); } return ci; diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/AnnotationSofaServiceTypeCheckFailTest.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/AnnotationSofaServiceTypeCheckFailTest.java index 013d6fa86..ff7d28d62 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/AnnotationSofaServiceTypeCheckFailTest.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/AnnotationSofaServiceTypeCheckFailTest.java @@ -24,6 +24,7 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; +import org.springframework.beans.factory.BeanCreationException; import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -68,7 +69,8 @@ public void testSofaServiceClassNotAssignableFromInterfaceType() throws IOExcept TestSofaServiceNotAssignableFromInterfaceTypeConfiguration.class); springApplication.setWebApplicationType(WebApplicationType.NONE); springApplication.setDefaultProperties(properties); - springApplication.run(); + + Assert.assertThrows(BeanCreationException.class, springApplication::run); String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding")); Assert diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/ClientFactoryTest.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/ClientFactoryTest.java index cc18cff3f..4a22fec90 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/ClientFactoryTest.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/ClientFactoryTest.java @@ -134,7 +134,7 @@ public void testBindingInstanceIsNotAssignableFromInterfaceType() throws IOExcep serviceParam.setInstance(new Object()); serviceParam.setInterfaceType(SampleService.class); serviceParam.addBindingParam(jvmBindingParam); - serviceClient.service(serviceParam); + Assert.assertThrows(Exception.class, ()-> serviceClient.service(serviceParam)); String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding")); Assert diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/XMLSofaServiceTypeCheckFailTest.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/XMLSofaServiceTypeCheckFailTest.java index e3c6e9b3b..af69e62ba 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/XMLSofaServiceTypeCheckFailTest.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/XMLSofaServiceTypeCheckFailTest.java @@ -66,7 +66,8 @@ public void testServiceBinding() throws IOException { SofaBindingTestIsNotAssignableFromInterfaceTypeConfiguration.class); springApplication.setWebApplicationType(WebApplicationType.NONE); springApplication.setDefaultProperties(properties); - springApplication.run(); + + Assert.assertThrows(Exception.class, springApplication::run); String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding")); Assert