In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about the operation of spring | springboot integration dubbo. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's follow the editor to have a look.
Project background
Now domestic small and medium-sized companies, remote calls are basically dubbo, of course, knife companies are no exception, we used to use the version of dubbo 2.4.x, although it can also be used, but in the pursuit of new projects and new technologies, we updated to the version of dubbo 2.7.x
The previous integration mode of springboot integrated dubbo application
Introduce jar package of dubbo and zk
@ ImportResource ({"classpath*:dubbo/*.xml"}) public class Start extends SpringBootServletInitializer
The dubbo.properties content is as follows:
Dubbo.container=logback,springdubbo.application.name=dubbo-servicedubbo.registry.address=zookeeper://zookeeper.xxx.com:2181dubbo.log4j.file=logs/dubbo-service.logdubbo.log4j.level=WARNdubbo.protocol.port=20782dubbo.protocol.dispatcher=messagedubbo.protocol.threadpool=fixeddubbo.protocol.threads=200
And dubbo.provider.xml.
At this time, you should be able to see the application registered on dubbo-admin.
New way of integration
With the last wave of multi-module shelves built with gradle, today we add dubbo to it.
Official documents:
Https://github.com/apache/dubbo-spring-boot-project
First introduce related dependencies. Note here that dependencies are placed in the service layer, because it is the service layer that needs to provide dubbo services. Of course, to save trouble, you can also put it in business-impl, because we will call the dubbo interface of other projects, but strictly speaking, the application of basic service only takes data from its own database and returns it to the business application through the dubbo interface. Therefore, in the basic application, the dependency can only be referred to the service layer, and the business application can be directed directly to the business-impl layer.
Service providing layer
Implementation 'org.springframework.boot:spring-boot-starter'
TestImplementation 'org.springframework.boot:spring-boot-starter-test' compile group:' org.apache.dubbo', name: 'dubbo-spring-boot-starter', version:' 2.7.1 'compile (group:' org.apache.dubbo', name: 'dubbo-dependencies-zookeeper' Version: '2.7.2') {exclude group:'org.slf4j'} compile (' org.apache.dubbo:dubbo:2.7.2') {exclude group:' org.springframework' exclude group:' javax.servlet' exclude group:' log4j'}
Configure in application.properties:
Dubbo.application.name=forest-servicedubbo.registry.address=zookeeper://zookeeper.xxx.com:30038dubbo.protocol.name=dubbodubbo.protocol.port=21899dubbo.config-center.address=zookeeper://zookeeper.xxx.com:30038dubbo.metadata-report.address=zookeeper://zookeeper.xxx.com:30038dubbo.scan.base-packages=com.platform.market.service.impl
The directory structure of this era code is as follows:
Among them, on the implementation class, you need to add the following two comments:
@ Service@Componentpublic class ItemServiceImpl implements ItemService
Note that it is the service annotation in the dubbo package
Then we can see the service we started in dubbo-admin
Service consumption layer
It's very simple here. In a word, change the @ Autowire we wrote before to @ Reference in the dubbo package.
That's it.
You only need to quote the registered address in the configuration file.
Dubbo.application.name=xxxx-xxxxdubbo.registry.address=zookeeper://zookeeper.xxx.com:30038 above is the operation process of spring | springboot integrating dubbo. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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.
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.