Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement springboot2.2.2 Integration dubbo

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shows you how to implement springboot2.2.2 integration dubbo, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Recently, I have been studying dubbo, thinking about taking some notes. I have never written a blog on csdn. Today, I offer it for the first time, , directly on the code.

First, create a parent project

4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.2.RELEASE com.dubbo demo01 1.0.0 pom Spring Boot2.x integrates dubbo api provider consumer UTF-8 UTF-8 1.8 2.7.5 4.2.0 3.4.12 org.apache.dubbo dubbo-spring-boot-starter ${dubbo.version} org.apache.curator curator-recipes ${curator.version} org.apache.zookeeper zookeeper ${zookeeper.version } org.springframework.boot spring-boot-devtools runtime true org.projectlombok lombok true

2. Create an api shared by providers and consumers

There is nothing to say about this module. Both providers and consumers need to use the interface api, and both providers and consumers need to introduce this module.

Demo01 com.dubbo 1.0.0 4.0.0 api

/ / all the annotations are lombok, which is really convenient for @ Data@Builder@NoArgsConstructor@AllArgsConstructor (access = AccessLevel.PRIVATE) public class User implements Serializable {private Integer id; private String name; private Integer age;}

Public interface UserService {User getUserById (Integer id);}

Third, create a provider

4.0.0 com.dubbo 1.0.0 demo01 com.dubbo provider 0.0.1-SNAPSHOT provider Demo project for Spring Boot org.springframework.boot spring-boot-starter-web org.apache.dubbo dubbo-spring-boot-starter org.apache.curator curator-recipes org.apache.zookeeper zookeeper com.dubbo api 1.0.0 org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine org.springframework.boot spring-boot-maven-plugin

Dubbo: application: # Application name name: user-provider protocol: # Protocol name name: dubbo # Protocol Port port: 20880 registry: # Registry address address: zookeeper://192.168.104.231:2181

Applications served by @ SpringBootApplication// must be configured with this @ DubboComponentScan ("com.dubbo.provider.service") public class ProviderApplication {public static void main (String [] args) {SpringApplication.run (ProviderApplication.class, args);}}

Component// this service is org.apache.dubbo.config.annotation.Service@Servicepublic class UserServiceImpl implements UserService {@ Override public User getUserById (Integer id) {User user = User.builder () .id (id) .name ("Zhang San") .age (20 + id) .build (); return user;}}

Fourth, create consumers

4.0.0 com.dubbo 1.0.0 demo01 com.dubbo consumer 0.0.1-SNAPSHOT consumer Demo project for Spring Boot org.springframework.boot spring-boot-starter-web org.apache.dubbo dubbo-spring-boot-starter org.apache.curator curator-recipes org.apache.zookeeper zookeeper com.dubbo api 1.0.0 org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine org.springframework.boot spring-boot-maven-plugin

# Port server: port: 8081dubbo: application: name: user-consumer protocol: name: dubbo port: 20880 registry: address: zookeeper://192.168.104.231:2181

@ SpringBootApplicationpublic class ConsumerApplication {public static void main (String [] args) {SpringApplication.run (ConsumerApplication.class, args);}}

@ RestController@RequestMapping ("/ user") public class ConsumerController {@ Reference private UserService userService; @ GetMapping ("/ {id}") public User getUserById (@ PathVariable int id) {return userService.getUserById (id);}}

Start and visit

Start provider

Start consumer

Browser access: http://localhost:8081/user/4

The above content is how to implement springboot2.2.2 integration dubbo. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report