You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/02/01 17:52:18 UTC

[GitHub] [dubbo] lifes opened a new issue #9647: 注解的方式配置,@ Configuration @Bean @DubboReference(若配置methods则报错)

lifes opened a new issue #9647:
URL: https://github.com/apache/dubbo/issues/9647


   env 
   dubbo3.0.5 
   
   
   1. 接口定义
   ```
   public interface Service2 {
   
       String sayHello(String name);
   
       String sayHello(ClientInfo clientInfo, String name);
   
       default CompletableFuture<String> sayHelloAsync(String name){
          return CompletableFuture.completedFuture(sayHello(name));
       }
   
       default CompletableFuture<String> sayHelloAsync(ClientInfo clientInfo, String name){
           return CompletableFuture.completedFuture(sayHello(clientInfo, name));
       }
   }
   ```
   2.
   
   ```
   @Configuration
   public class DubboConsumerConfiguration {
   
       @Bean
       @DubboReference(
               check = false,
           methods = {
                // 如果删除这一行,则不报错
                //仅仅配置@Method(name = "sayHelloAsync"),报错
               //换成xml配置不报错
               //@DubboReference直接在filed上注入不报错
               @Method(name = "sayHelloAsync", onreturn = "service2_sayHelloAsync.onreturn")
           }
       )
       public ReferenceBean<Service2> service2() {
           return new ReferenceBean<>();
       }
   }
   
   ```
   3. 回调接口
    ```
     public interface Notify {
   
       void onreturn(String ret, String req);
       void onthrow(Throwable ex, String req);
   
   }
   ```
   ```
   @Component("service2_sayHelloAsync")
   public class NotifyImpl implements Notify{
       @Override
       public void onreturn(String ret, String name) {
           System.out.println("callback调用");
           var clientAtt = RpcContext.getClientAttachment().getObjectAttachments();
           var serverAtt = RpcContext.getServerAttachment().getObjectAttachments();
           var serverCtx = RpcContext.getServerContext();
           var serviceCtx = RpcContext.getServiceContext();
           System.out.println("clientAtt" + JSON.toJSONString(clientAtt));
           System.out.println("serverAtt" + JSON.toJSONString(serverAtt));
           System.out.println("serverCtx" + JSON.toJSONString(serverCtx.getObjectAttachments()));
           System.out.println("serviceCtx" + JSON.toJSONString(serviceCtx.getObjectAttachments()));
           System.out.println("callback调用2");
       }
   
       @Override
       public void onthrow(Throwable ex, String name) {
   
       }
   }
   ```
   报错
   
   > Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service2' defined in class path resource [org/chm/dubboexample/application1/DubboConsumerConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NullPointerException
   > 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1708)
   > 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:581)
   > 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)
   > 	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
   > 	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
   > 	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
   > 	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
   > 	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
   > 	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
   > 	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
   > 	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)
   > 	... 19 more
   > Caused by: java.lang.NullPointerException
   > 	at org.apache.dubbo.config.spring.reference.ReferenceBeanSupport.convertToString(ReferenceBeanSupport.java:174)
   > 	at org.apache.dubbo.config.spring.reference.ReferenceBeanSupport.convertToString(ReferenceBeanSupport.java:186)
   > 	at org.apache.dubbo.config.spring.reference.ReferenceBeanSupport.convertToString(ReferenceBeanSupport.java:178)
   > 	at org.apache.dubbo.config.spring.reference.ReferenceBeanSupport.generateReferenceKey(ReferenceBeanSupport.java:129)
   > 	at org.apache.dubbo.config.spring.reference.ReferenceBeanSupport.generateReferenceKey(ReferenceBeanSupport.java:243)
   > 	at org.apache.dubbo.config.spring.reference.ReferenceBeanManager.addReference(ReferenceBeanManager.java:70)
   > 	at org.apache.dubbo.config.spring.ReferenceBean.afterPropertiesSet(ReferenceBean.java:242)
   > 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1767)
   > 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1704)
   > 	... 29 more
   > 2022-02-02 00:28:14.033  WARN 11163 --- [       Thread-5] c.a.nacos.common.notify.NotifyCenter     : [NotifyCenter] Start destroying Publisher
   > 2022-02-02 00:28:14.033  WARN 11163 --- [       Thread-5] c.a.nacos.common.notify.NotifyCenter     : [NotifyCenter] Destruction of the end
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] CrazyHZM closed issue #9647: 注解的方式配置,@ Configuration @Bean @DubboReference(若配置methods则报错)

Posted by GitBox <gi...@apache.org>.
CrazyHZM closed issue #9647:
URL: https://github.com/apache/dubbo/issues/9647


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] monkeycraps commented on issue #9647: 注解的方式配置,@ Configuration @Bean @DubboReference(若配置methods则报错)

Posted by GitBox <gi...@apache.org>.
monkeycraps commented on issue #9647:
URL: https://github.com/apache/dubbo/issues/9647#issuecomment-1028520242


   parameters 为空时,会被转为null,并报错;这个参数文档看还没有
   
   ![image](https://user-images.githubusercontent.com/2322555/152266360-85e63aa3-e6f5-47da-90b2-0dac63961cc0.png)
   
   ![image](https://user-images.githubusercontent.com/2322555/152266408-55b42639-b4ec-4706-ba0a-98217afabe5e.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] BurningCN commented on issue #9647: 注解的方式配置,@ Configuration @Bean @DubboReference(若配置methods则报错)

Posted by GitBox <gi...@apache.org>.
BurningCN commented on issue #9647:
URL: https://github.com/apache/dubbo/issues/9647#issuecomment-1034443807


   两位谁方便提交个pr吗?没有的话就我来处理下


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] BurningCN commented on issue #9647: 注解的方式配置,@ Configuration @Bean @DubboReference(若配置methods则报错)

Posted by GitBox <gi...@apache.org>.
BurningCN commented on issue #9647:
URL: https://github.com/apache/dubbo/issues/9647#issuecomment-1033292003


   @monkeycraps 
   看了下,的确是这样。目前我的两个解决方式是在`DubboAnnotationUtils#convertParameters`在执行`if (ArrayUtils.isEmpty(parameters))`的时候返回`Collections.emptyMap()`而不是原有返回`null`,或者如下调整也可以解决
   ![image](https://user-images.githubusercontent.com/43363120/153113310-9bee5094-1d97-4348-a3c7-0746baf14170.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] monkeycraps commented on issue #9647: 注解的方式配置,@ Configuration @Bean @DubboReference(若配置methods则报错)

Posted by GitBox <gi...@apache.org>.
monkeycraps commented on issue #9647:
URL: https://github.com/apache/dubbo/issues/9647#issuecomment-1032423929


   我是按上面的代码写的,没有什么特别,很好复现,直接在 dubbo 源代码的 demo 里复现的 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] BurningCN commented on issue #9647: 注解的方式配置,@ Configuration @Bean @DubboReference(若配置methods则报错)

Posted by GitBox <gi...@apache.org>.
BurningCN commented on issue #9647:
URL: https://github.com/apache/dubbo/issues/9647#issuecomment-1032422062


   能否给下完整的项目工程用例代码


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] chenhuaming commented on issue #9647: 注解的方式配置,@ Configuration @Bean @DubboReference(若配置methods则报错)

Posted by GitBox <gi...@apache.org>.
chenhuaming commented on issue #9647:
URL: https://github.com/apache/dubbo/issues/9647#issuecomment-1033256995


   > 能否给下完整的项目工程用例代码
   
   官方的示例代码,添加
   
   @Configuration
   public class DubboConsumerConfiguration {
   
       @Bean
       @DubboReference(
               check = false,
           methods = {
                // 如果删除这一行,则不报错
                //仅仅配置@Method(name = "sayHelloAsync"),报错
               //换成xml配置不报错
               //@DubboReference直接在filed上注入不报错
               @Method(name = "sayHelloAsync", onreturn = "service2_sayHelloAsync.onreturn")
           }
       )
       public ReferenceBean<Service2> service2() {
           return new ReferenceBean<>();
       }
   }
   
   即可复现


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] BurningCN edited a comment on issue #9647: 注解的方式配置,@ Configuration @Bean @DubboReference(若配置methods则报错)

Posted by GitBox <gi...@apache.org>.
BurningCN edited a comment on issue #9647:
URL: https://github.com/apache/dubbo/issues/9647#issuecomment-1033292003






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] CrazyHZM commented on issue #9647: 注解的方式配置,@ Configuration @Bean @DubboReference(若配置methods则报错)

Posted by GitBox <gi...@apache.org>.
CrazyHZM commented on issue #9647:
URL: https://github.com/apache/dubbo/issues/9647#issuecomment-1084327410


   Resolved at #9693 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org