springboot1.x big gap and springboot2.x integration, based on the latest 2.x integration, the use of pure annotation mode
1. the dependency of the pom file is introduced, and the maven repository has two Apache and alibaba
Dubbo has already been incubated, broke out of the shell, and became an Apache top-level project . Here we quote Apache's maven dependency
Using maven aggregation project, the structure is shown in the figure
Detailed hierarchical structure diagram
api Common entity and service interface provider-log log service provider provider-message message service provider consumer consumer
The top pom.xml introduces spring-boot-starter-parent, using the new version 2.1.6.release
3.aggregation modules
<modules> <module>api</module> <module>provider-log</module> <module>provider-message</module> </modules> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
The api module is used to provide the dubbo service interface, so adding the dependency of dubbo to the api is somewhat inappropriate
api->pom.xml
<dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>2.7.1</version> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo</artifactId> <version>2.7.1</version> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-dependencies-zookeeper</artifactId> <version>2.7.1</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> </exclusions> <type>pom</type> </dependency>
The remaining three projects all introduce the parent project , rely on the introduction of api , spring-boot-starter-web is optional , if you provide web services, you can add it, if you don’t provide services, you don’t need to add it.
<parent> <groupId>com.chy.wx</groupId> <artifactId>spring-boot-dubbo</artifactId> <version>1.0-SNAPSHOT</version> </parent> <dependencies> <dependency> <groupId>com.chy.wx</groupId> <artifactId>sea-api</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
api adds two entities and two services, which is more distinguishable
Two providers, in order to be more distinguishable, application configuration, here uses yuml syntax.
The difference with springboot1.x is that dubbo starts separately, and there is no spring in front.
server: port: 8081 dubbo: application: name: sea-provider-log registry: protocol: zookeeper address: 192.168.1.222:2181 protocol: name: dubbo port: 20887 version: 1.0.0 scan: base-packages: com.log
The published service is annotated with @Service , and the scanned implementation class is loaded above, here is dubbo the annotation
Add @EnableDubbo annotation to the startup class
Enter dubbo through the following command
telnet 192.168.1.222 21880
View published services using ls
The following shows that ErrorLogService was successfully released and the version is 1.0.0
For more commands, see Telnet Command Reference Manual