Dubbo+SpringBoot Integration: the problem of dependency injection Null Pointer Exception

I use Dubbo+SpringBoot to build micro services
controller and service belong to two services
there are the following classes

@RestController
@RequestMapping("product")
public class ProductController{

    @Reference(version="1.0.0")
    ProductService productService;
    
    @GetMapping("create")
    public String createProduct(){
        return productService.createProduct();
    }
}


@Component
@Service(version = "1.0.0")
public class ProductServiceImpl implements ProductService {
   @Override
    public String createProduct(){
        return "created";
    }
}

I found that if I start the service service first, then start the controller service and run OK
but if I start the controller service first and then start the service service, productService is null, and Null Pointer Exception appears

my understanding is that because the service is started, the productService dependency injection in controller cannot find an instance and the injection fails.
but in this case, if there are two service microservices, if a class in An and BMagie A needs a service from a class in B, and a class in B needs a service from a class in A, then whoever starts it first will have a problem.
what"s going on?

Mar.22,2021

  1. it is recommended that you take a closer look at the Dubbo document and find some examples to take a look at
  2. for Reference, it is recommended that you create a new folder to separate Reference, and avoid repeating information such as Reference (version= "1.0.0")
  3. .
  4. Dubbo has service registration and discovery. If A depends on BMaga, start first, and then start B. 1 you can set that the dependent check=false of B in A does not check. When 2B starts, it will push / notify all systems that have subscribed to the service ~ (in fact, it is still 1. See more documents)

spring mvc annotations and dubbo annotations configured in two different context causes
the simpler solution is not to use dubbo annotations in controller


dubbo=2.6.1

        <dependency>
            <groupId>com.101tec</groupId>
            <artifactId>zkclient</artifactId>
            <version>0.10</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.spring.boot</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
//
    @Reference(version="0.0.1", timeout = 5000, check= false)
    private HelloWorldService helloWorldService;
// 
@SpringBootApplication
@EnableDubboConfiguration
@EnableAspectJAutoProxy

Service provider

@Service(version = "0.0.1", timeout = 5000, interfaceClass = HelloWorldService.class)
public class HelloWorldServiceImpl implements HelloWorldService {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    /*
     * (non-Javadoc)
     * 
     * @see org.bjhxxt.shop.service.HelloWorldService-sharpsayHello(java.lang.String)
     */
    @Override
    public String sayHello(String name) {
        logger.debug("hello dubbo service");
        return "Hello dubbo for " + name;
    }

}

personal test is OK, of course, except for the ones above, if there are any omissions, not necessarily.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bdd47c-39711.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bdd47c-39711.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?