In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the way of springboot distributed integration of dubbo". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the way of springboot distributed integration of dubbo"?
Dubbo is an open source distributed service framework of Alibaba. Its biggest feature is that it is structured in a hierarchical manner, which can be used to decouple (or loosely couple each layer to the maximum). From the point of view of the service model, Dubbo adopts a very simple model, either the provider provides the service or the consumer consumes the service, so the roles of service provider (Provider) and service consumer (Consumer) can be abstracted from this point.
1. Service provider configuration / / additional introduction of jar package provider com.alibaba.boot dubbo-spring-boot-starter 0.2.0 com.github.sgroschupf zkclient 0.1
Spring configuration mode
Springboot configuration mode
# configuration of dubbo # Service name dubbo.application.name=user-provider# registry address dubbo.registry.address=zookeeper://192.168.192.3:2181# protocol and port number dubbo.protocol.name=dubbodubbo.protocol.port=11111
The way the service is published
Add comments to the corresponding implementation class
The annotation of import com.alibaba.dubbo.config.annotation.Service;import com.oracle.shopping.user.mapper.MenuMapper;import com.oracle.shopping.user.po.Menu;import com.oracle.shopping.user.service.MenuService;import javax.annotation.Resource;@Service / / dubbo indicates that publishing the annotation of this class @ org.springframework.stereotype.Service//spring indicates that the class public class MenuServiceImpl implements MenuService {@ Resource private MenuMapper menuMapper will be instantiated at startup @ Override public int deleteByPrimaryKey (String id) {return menuMapper.deleteByPrimaryKey (id);} @ Override public int insert (Menu record) {return menuMapper.insert (record);} @ Override public int insertSelective (Menu record) {return menuMapper.insertSelective (record);} @ Override public Menu selectByPrimaryKey (String id) {return menuMapper.selectByPrimaryKey (id) @ Override public int updateByPrimaryKeySelective (Menu record) {return menuMapper.updateByPrimaryKeySelective (record);} @ Override public int updateByPrimaryKey (Menu record) {return menuMapper.updateByPrimaryKey (record);}}
Start the packet sweeper that adds dubbo to the class and set the scan path
@ SpringBootApplication@MapperScan ("com.oracle.shopping.user.mapper") @ EnableTransactionManagement@DubboComponentScan ("com.oracle.shopping.user.service.impl") public class UserProviderApp {public static void main (String [] args) {SpringApplication.run (UserProviderApp.class, args);} 2. Service consumers subscribe to com.alibaba.boot dubbo-spring-boot-starter 0.2.0 com.github.sgroschupf zkclient 0.1
Spring configuration mode
Dependency injection and invocation in controller
@ Controller@RequestMapping ("/ user") public class UserController {/ / dynamic proxy class generated by dynamic proxy @ Autowired (required = false) private UserService userService; / / does not check to prevent errors from running @ Autowired (required = false) private OrderService orderService; @ RequestMapping ("/ a") public @ ResponseBody User detail () {return userService.findUserById (1) @ RequestMapping ("/ b") public @ ResponseBody Orders details () {return orderService.findUserById (1);}}
Springboot configuration mode
# specify your own name dubbo.application.name=user-consumer# specify the address of the registry dubbo.registry.address=zookeeper://192.168.192.3:2181
Use annotations in controller to declare the services to be used (implementation classes)
@ RestController@RequestMapping ("/ user") public class UserController {/ / indicates the service to be used @ Reference (interfaceName = "com.oracle.shopping.user.service.UserService") private UserService userService; @ Autowired private RedisTemplate redisTemplate; @ RequestMapping ("/ detail") public User detail (String id) {return userService.selectByPrimaryKey (id);}}
Set the scan path for dobbo comments in the startup class
@ SpringBootApplication@DubboComponentScan ("com.oracle.shopping.user.controller") public class UserConsumerApp {public static void main (String [] args) {SpringApplication.run (UserConsumerApp.class) }} Thank you for your reading. the above is the content of "what is the way of springboot distributed integration of dubbo". After the study of this article, I believe you have a deeper understanding of what is the way of distributed integration of dubbo by springboot. The specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.