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?