This example is based on version 2.7.3 of dubbo-spring-boot-project. It may be outdated according to the new version. Please pay attention when reading.
There are many examples on how to use dubbo in spring-boot, but because of the long time span, many examples are outdated, and everything should be subject to official examples.
If you search for the project integrated with dubbo and spring-boot on github, you may find the following two, respectively
- alibaba / dubbo-spring-boot-starter< /li>
- apache / dubbo-spring-boot-project
The first project has been archived and will not be updated, so we will use the second project Whichever, don’t make a mistake.
Open the home page of the second project and start browsing the Getting Started chapter in the README. This chapter shows us an example of no registration center (dubbo.registry.address=N/A).
But it can’t run. After the consumer starts, the service provider cannot be found, and an error of Not found exported service is reported.
The solution is as follows:
It is necessary to specify the version in the url when the consumer Reference service provider is used. In fact, the version has been specified, but I do not know why I have to specify it again in the url.
// @Reference(version = "1.0.0", url = "dubbo://127.0.0.1:12345")
@Reference(version = "1.0.0", url = "dubbo://127.0.0.1:12345?version=1.0.0")
private DemoService demoService;
In addition, the pom dependency in Getting Started is also relatively simple, omitting spring- For the dependencies originally needed for boot, you can refer to the dependencies in my pom in this repaired version.
Source code address: https://github.com/kongxiangxin/dubbo-spring-boot-samples