Open HuamingChen opened 5 years ago
Did you change the code ?
是的,我在DefaultDemoService中故意增加了一个异常 代码如下 `@Service(version = "1.0.0") public class DefaultDemoService implements DemoService {
/**
* The default value of ${dubbo.application.name} is ${spring.application.name}
*/
@Value("${dubbo.application.name}")
private String serviceName;
public String sayHello(String name) {
int i=1/0;
return String.format("[%s] : Hello, %s", serviceName, name);
}
}`
然后就抛出了上诉的异常。 我个人认为只抛出Caused by: java.lang.ArithmeticException: / by zero才是正确的, 不明白的是,为什么还会抛出Caused by: java.lang.reflect.InvocationTargetException: null这个异常, 因为能力问题,现在还弄不明白为什么会报这个错误。
而在我实际项目只是采用@ControllerAdvice @ExceptionHandler 增加UndeclaredThrowableException异常的处理,但是这并不是我最想要的
希望各路大神指导一下,或者帮忙解决一下,十分感谢
Did you change the code ? 是的,我在DefaultDemoService中故意增加了一个异常 代码如下 `@service(version = "1.0.0") public class DefaultDemoService implements DemoService {
/**
* The default value of ${dubbo.application.name} is ${spring.application.name}
*/
@Value("${dubbo.application.name}")
private String serviceName;
public String sayHello(String name) {
int i=1/0;
return String.format("[%s] : Hello, %s", serviceName, name);
}
}`
然后就抛出了上诉的异常。 我个人认为只抛出Caused by: java.lang.ArithmeticException: / by zero才是正确的, 不明白的是,为什么还会抛出Caused by: java.lang.reflect.InvocationTargetException: null这个异常, 因为能力问题,现在还弄不明白为什么会报这个错误。
而在我实际项目只是采用@ControllerAdvice @ExceptionHandler 增加UndeclaredThrowableException异常的处理,但是这并不是我最想要的
希望各路大神指导一下,或者帮忙解决一下,十分感谢
Is there a complete sample code?
Is there a complete sample code?
There are no previous code examples. But I learned about the Dubbo exception handling mechanism and used other solutions. Thank you very much!
My previous problem was: I threw an exception in the provider, and the exception fetched from the consumer (after passing through the Dubbo exception handling mechanism) was not the same as the exception type retrieved from the provider.
It has just been simulated in the latest dubbo-spring-boot-demo-2.7.7 project and cannot be reproduced (possibly fixed). The problematic version is dubbo-spring-boot-starter-2.7.0
Due to network reasons, can not upload code, please forgive me. Change the code of zookeeper samples as follows
org.apache.dubbo . spring.boot.demo . provider.service.DefaultDemoService `/*
import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.spring.boot.demo.consumer.DemoService; import org.springframework.beans.factory.annotation.Value;
/**
@since 2.7.0 */ @Service(version = "${demo.service.version}") public class DefaultDemoService implements DemoService {
/**
public String sayHello(String name) { int i=1/0; return String.format("[%s] : Hello, %s", serviceName, name); } } `
org.apache.dubbo . spring.boot.demo . consumer.bootstrap.DubboRegistryZooKeeperConsumerBootstrap
`/*
import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.spring.boot.demo.consumer.DemoService;
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;
/**
Dubbo Registry ZooKeeper Consumer Bootstrap */ @EnableAutoConfiguration @RestController public class DubboRegistryZooKeeperConsumerBootstrap {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Reference(version = "${demo.service.version}") private DemoService demoService;
public static void main(String[] args) { SpringApplication.run(DubboRegistryZooKeeperConsumerBootstrap.class); }
/@Bean public ApplicationRunner runner() { return args -> { logger.info(demoService.sayHello("mercyblitz")); }; }/
@GetMapping public void test(){ try { demoService.sayHello("mercyblitz"); }catch (Exception e){ e.printStackTrace(); } } } `
我在测试dubbo异常处理的时候 发现这个异常
谁能帮我看看 要如何解决 具体异常如下