apache / dubbo-spring-boot-project

Spring Boot Project for Apache Dubbo
https://dubbo.apache.org
Apache License 2.0
5.41k stars 1.88k forks source link

我在使用自动配置demo的时候 测试异常 #455

Open HuamingChen opened 5 years ago

HuamingChen commented 5 years ago

我在测试dubbo异常处理的时候 发现这个异常

Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
    at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.invoke(ReferenceAnnotationBeanPostProcessor.java:158) ~[dubbo-2.7.0.jar:2.7.0]
    ... 8 common frames omitted

谁能帮我看看 要如何解决 具体异常如下

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-02-22 10:22:44.020 ERROR 9220 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Failed to execute ApplicationRunner
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:807) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:794) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:324) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.apache.dubbo.spring.boot.demo.consumer.bootstrap.DubboAutoConfigurationConsumerBootstrap.main(DubboAutoConfigurationConsumerBootstrap.java:42) [classes/:na]
Caused by: java.lang.reflect.UndeclaredThrowableException: null
    at com.sun.proxy.$Proxy38.sayHello(Unknown Source) ~[na:na]
    at org.apache.dubbo.spring.boot.demo.consumer.bootstrap.DubboAutoConfigurationConsumerBootstrap.lambda$runner$0(DubboAutoConfigurationConsumerBootstrap.java:48) [classes/:na]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:804) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    ... 5 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
    at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.invoke(ReferenceAnnotationBeanPostProcessor.java:158) ~[dubbo-2.7.0.jar:2.7.0]
    ... 8 common frames omitted
Caused by: java.lang.ArithmeticException: / by zero
    at org.apache.dubbo.spring.boot.demo.provider.service.DefaultDemoService.sayHello(DefaultDemoService.java:39) ~[na:na]
    at org.apache.dubbo.common.bytecode.Wrapper1.invokeMethod(Wrapper1.java) ~[na:na]
    at org.apache.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:47) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:86) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker.invoke(DelegateProviderMetaDataInvoker.java:56) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:63) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:88) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:79) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:78) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:138) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:39) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:73) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:108) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:103) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:200) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:51) ~[dubbo-2.7.0.jar:2.7.0]
    at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:57) ~[dubbo-2.7.0.jar:2.7.0]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_161]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_161]
    at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_161]
mercyblitz commented 5 years ago

Did you change the code ?

HuamingChen commented 5 years ago

是的,我在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异常的处理,但是这并不是我最想要的

希望各路大神指导一下,或者帮忙解决一下,十分感谢

HuamingChen commented 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异常的处理,但是这并不是我最想要的

希望各路大神指导一下,或者帮忙解决一下,十分感谢

daniel-liy commented 4 years ago

Is there a complete sample code?

HuamingChen commented 4 years ago

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;

/**

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;

/**