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

while I use @Autowired In CommandLineRunner To inject dubb proxy . spring could not found the beanDefinition #232

Closed dongyuanlongwang closed 5 years ago

dongyuanlongwang commented 6 years ago

DemoService is a dubbo proxy 。

expected: inject and worked fine

actually: Field demoService in XXX.ConsumerCommandLineRunner required a bean of type 'XXX.api.DemoService' that could not be found.

code is here

@Component
@Slf4j
public class ConsumerCommandLineRunner implements CommandLineRunner {

    @Autowired
    private DemoService demoService;

    @Override
    public void run(String... args) throws Exception {
        log.info(demoService.sayHello("world"));

        log.info("☺");
    }
}

only use this it cloud work

    @Reference
    private DemoService demoService;
mercyblitz commented 5 years ago

Please add Dubbo 2.6.5 in order to override indirectly dependencies:

<dependency>
    <groupId>com.alibaba.boot</groupId>
    <artifactId>dubbo-spring-boot-starter</artifactId>
    <version>0.2.0</version>
</dependency>

<!-- Dubbo -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>dubbo</artifactId>
    <version>2.6.5</version>
</dependency>
<!-- Spring Context Extras -->
<dependency>
    <groupId>com.alibaba.spring</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>1.0.2</version>
</dependency>

There was a legacy issue in Dubbo.