You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "dongdongqin (GitHub)" <gi...@apache.org> on 2019/01/26 01:42:05 UTC

[GitHub] [incubator-dubbo-spring-boot-project] dongdongqin opened issue #415: springboot dubbo rest protocol, as consumer, @Reference is null, how to solve?

code:
  @EnableDubbo
@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

#dubbo.application.name=rest-consumer

#dubbo.protocols.rest.name = rest
#dubbo.protocols.rest.port = 8889
#dubbo.protocols.rest.server=tomcat
#dubbo.registry.address=zookeeper://127.0.0.1:2181


@RestController
@RequestMapping(path = "/template")
public class IndexController {

    @Reference
    AnotherUserRestService anotherUserRestService;
    @RequestMapping(value = "/getData", method = RequestMethod.GET)
    public String index() {
        System.out.println(anotherUserRestService.getUser(1L));
        return "index";
    }

anotherUserRestService is null.

it seems that springboot component scan and dubbo reference bean,  are in different context.  From log,
i can see that dubbo:reference,   proxy object is already created. 
However, below object reference is always null.
    @Reference
    AnotherUserRestService anotherUserRestService;



Solution:

@ImportResource("classpath:rest-consumer.xml")
@EnableDubbo
@SpringBootApplication

rest-consumer.xml

dubbo:application name="rest-consumer" owner="programmer" organization="dubbo"/>

    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>

    <dubbo:reference id="anotherUserRestService"
                     interface="org.apache.dubbo.samples.rest.api.facade.AnotherUserRestService"/>
and then it works.

the protocol is rest.
Does any solution that we can use annotation to get the proxy object ?


[ Full content available at: https://github.com/apache/incubator-dubbo-spring-boot-project/issues/415 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo-spring-boot-project] dongdongqin closed issue #415: springboot dubbo rest protocol, as consumer, @Reference is null, how to solve?

Posted by "dongdongqin (GitHub)" <gi...@apache.org>.
[ issue closed by dongdongqin ]

[ Full content available at: https://github.com/apache/incubator-dubbo-spring-boot-project/issues/415 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo-spring-boot-project] dongdongqin commented on issue #415: springboot dubbo rest protocol, as consumer, @Reference is null, how to solve?

Posted by "dongdongqin (GitHub)" <gi...@apache.org>.
@Reference need to add version, or group, it will work.

[ Full content available at: https://github.com/apache/incubator-dubbo-spring-boot-project/issues/415 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org