In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to use Dubbo distributed service in SpringBoot? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
Before the transformation
This is how you used to use Dubbox in SpringBoot. First simply record the version, Dubbox-2.8.4, zkclient-0.6, zookeeper-3.4.6.
The spring-context-dubbo.xml configuration file introduced into the project is as follows:
The startup class introduces the following comments:
@ SpringBootApplication@ImportResource ({"classpath:spring-context-dubbo.xml"}) public class Application {private static final Logger logger = Logger.getLogger (Application.class); public static void main (String [] args) throws InterruptedException, IOException {logger.info ("payment project starts");}} after transformation
However, SpringBoot introduces a new concept, SpringBoot Starter, which effectively reduces the complexity of the project development process and has a very good effect on simplifying the development operation.
The concept of starter
Starter will include all the dependencies used, avoiding the hassle of developers introducing dependencies themselves.
It should be noted that different starter are designed to solve different dependencies, so their internal implementations may be very different. For example, the starter of jpa and the starter of Redis may be different, this is because the essence of starter is synthesize, which is a layer of abstraction at the logical level, maybe this idea is a bit similar to Docker, because they are all doing a "wrapping" operation, if you know what problem Docker is to solve. Maybe you can use Docker and starter as an analogy.
The realization of starter
Although different starter implementations vary, they basically use two of the same content: ConfigurationProperties and AutoConfiguration.
Because Spring Boot firmly believes in the idea that conventions are greater than configurations, we use ConfigurationProperties to save our configurations, and these configurations can have a default value, that is, if we do not actively overwrite the original configuration, the default value will take effect, which is very useful in many cases.
In addition, starter's ConfigurationProperties allows all configuration properties to be aggregated into one file (usually application.properties in the resources directory), so we bid farewell to XML hell in the Spring project.
The overall Logic of starter
Better than Dubbo, of course, will also create their own starter to cater to the popularity of Spring Boot.
Here we use a newer version of Dubbo, and pom.xml introduces the following:
Com.alibaba dubbo 2.6.2 com.alibaba.spring.boot dubbo-spring-boot-starter 2.0.0 org.apache.curator curator-recipes 4.0.1
Application.properties configuration:
# # configuring spring.dubbo.application.id=springboot_payspring.dubbo.application.name=springboot_payspring.dubbo.registry.address=zookeeper://192.168.1.127:2181spring.dubbo.provider.threads=10spring.dubbo.provider.threadpool=fixedspring.dubbo.provider.loadbalance=roundrobinspring.dubbo.server=truespring.dubbo.protocol.name=dubbo for dubbo springboot
Add the following comments to the startup class:
@ EnableDubboConfiguration@SpringBootApplicationpublic class Application {private static final Logger logger = Logger.getLogger (Application.class); public static void main (String [] args) throws InterruptedException, IOException {logger.info ("payment project startup");}}
Configuration of the relevant exposure interface implementation:
Import org.springframework.stereotype.Component;import com.alibaba.dubbo.config.annotation.Service;@Service@Componentpublic class AliPayServiceImpl implements IAliPayService {/ / omit code} this is the answer to the question about how to use Dubbo distributed service in SpringBoot. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.