zoukankan      html  css  js  c++  java
  • 架构实战项目心得(七):使用SpringBoot+Dubbo+Mybatisplus+Oracle搭建后台项目框架(一)

    本节将简单整合SpringBoot+Duboo吐舌头

            1、Zookeeper的安装:

    1 从官网下载你喜欢的zookeeper的版本:

                       http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

    2 解压到你指定的目录,我的是xx/software/zookeeper
    3 修改/conf 文件夹下的zoo_sample.cfg,改名为zoo.cfg,并且修改里面的内容为:
    tickTime=2000
    dataDir=xx/software/data
    dataLogDir=xx/software/log
    clientPort=2181
                       也就是说你要创建两个目录data和log,来保存数据文件和日志文件
    4 回到zookeeper目录,进入bin目录,./zkServer.sh 启动zookeeper
    5 可以使用./zkCli.sh 来进入zookeeper的环境,并且进行简单的操作。不过本人推荐使用dubbo管控台来操作。
    2、dubbo管控台:
    1 从 https://pan.baidu.com/s/1rJf4-Y4-2RLq1Gy4NQsdZQ 密码:2vfz 下载dubbo的管控台。

    2 然后在一个tomcat中解压,解压后修改里面一个配置文件dubbo.proerties,修改IP为你的zookeeper服务器的地址。     

    dubbo.registry.address=zookeeper://xxx.xxx.xxx.xxx:2181    
    dubbo.admin.root.password=root	    
    dubbo.admin.guest.password=guest
        后面两个参数可以根据你的兴趣来修改。

    3 重新启动dubbo管控台,默认账号root,密码root,就进入dubbo管控台主页,并且此时已经连接上你的zookeeper。

    3、SpringBoot搭建后台框架:
    1 要使用Dubbo,最基本需要两个项目,一个是用来提供服务(ServiceProvider),一个用来消费服务(ServiceConsumer)。也可以将服务的接口专门提出来写一个项目(ServiceAPI),然后让ServiceProvider去调用ServiceAPI所定义的服务。本项目使用的是SpringBoot做为搭建框架。
    2 在IDEA中,创建一个maven项目,命名为dubbo-parent,作为所有项目的父项目,用来管理版本信息,pom文件的部分内容为:
    <modules>
        <module>architecture-dubbo-api</module>
        <module>architecture-dubbo-consumer</module>
        <module>architecture-dubbo-provider</module>
    </modules>
    <properties>
    <!-- 父类统一管理版本信息 -->
        <junit.version>4.12</junit.version>
        <dubbo-spring-boot>1.0.0</dubbo-spring-boot>
        <zookeeper.version>3.4.10</zookeeper.version>
        <dubbo.version>2.5.6</dubbo.version>
    </properties>
    3 在以上项目右键创建一个Module,命名为dubbo-service-provider,用来暴露服务,此项目的pom文件部分内容为:
                <!-- 使用另外一种方式,不继承parent,使用scope=import导入的方式使用Spring Boot -->
    		<dependencyManagement>
    			<dependencies>
    				<dependency>
    					<!-- Import dependency management from Spring Boot -->
    					<groupId>org.springframework.boot</groupId>
    					<artifactId>spring-boot-dependencies</artifactId>
    					<version>1.5.6.RELEASE</version>
    					<type>pom</type>
    					<scope>import</scope>
    				</dependency>
    			</dependencies>
    		</dependencyManagement>
    		<dependencies>
    			<!-- Spring Boot Dubbo 依赖 -->
    			<dependency>
    				<groupId>io.dubbo.springboot</groupId>
    				<artifactId>spring-boot-starter-dubbo</artifactId>
    				<version>${dubbo-spring-boot}</version>
    			</dependency>
    			<!-- Spring Boot Test 依赖 -->
    			<dependency>
    				<groupId>org.springframework.boot</groupId>
    				<artifactId>spring-boot-starter-test</artifactId>
    				<scope>test</scope>
    			</dependency>
    			<!-- Junit -->
    			<dependency>
    				<groupId>junit</groupId>
    				<artifactId>junit</artifactId>
    				<version>${junit.version}</version>
    			</dependency>
    			<dependency>
    				<groupId>org.apache.zookeeper</groupId>
    				<artifactId>zookeeper</artifactId>
    				<version>${zookeeper.version}</version>
    			</dependency>
    			<dependency>
    				<groupId>com.alibaba</groupId>
    				<artifactId>dubbo</artifactId>
    				<version>${dubbo.version}</version>
    			</dependency>
    		</dependencies>

    4 application.yml文件为:

    # Dubbo 服务提供者配置
    spring:
        dubbo:
            application:
                name: provider
            registry:
                address: zookeeper://xxx.xxx.xxx.xxx:2181 #zookeeper的注册中心
            protocol:
                name: dubbo
                port: 20880
            scan: com.laowang.service.impl #这里是你要暴露服务的包的完整路径  

    # Dubbo 服务提供者配置
    spring:
        dubbo:
            application:
                name: provider
            registry:
                address: zookeeper://xxx.xxx.xxx.xxx:2181 #zookeeper的注册中心
            protocol:
                name: dubbo
                port: 20880
            scan: com.laowang.service.impl #这里是你要暴露服务的包的完整路径  

    5 在父项目右键创建一个Module,命名为dubbo-service-consumer,用来消费服务,此项目的pom文件部分内容为:
        
                <!-- 使用另外一种方式,不继承parent,使用scope=import导入的方式使用Spring Boot -->
    		<dependencyManagement>
    			<dependencies>
    				<dependency>
    					<!-- Import dependency management from Spring Boot -->
    			         	<groupId>org.springframework.boot</groupId>
    					<artifactId>spring-boot-dependencies</artifactId>
    					<version>1.5.6.RELEASE</version>
    					<type>pom</type>
    					<scope>import</scope>
    				</dependency>
    			</dependencies>
    		</dependencyManagement>
    		<dependencies>
    			<dependency>
    				<groupId>org.springframework.boot</groupId>
    				<artifactId>spring-boot-starter</artifactId>
    			</dependency>
    		        <!-- Spring Boot Dubbo 依赖 -->
    		        <dependency>
    				<groupId>io.dubbo.springboot</groupId>
    				<artifactId>spring-boot-starter-dubbo</artifactId>
    				<version>${dubbo-spring-boot}</version>
    			</dependency>
    			<!-- 依赖服务暴露项目 -->
    			<dependency>
    				<groupId>com.laowang</groupId>
    				<artifactId>architecture-dubbo-provider</artifactId>
    				<version>1.0-SNAPSHOT</version>
    			</dependency>
    			<!-- springboot web 依赖 -->
    			<dependency>
    		        	<groupId>org.springframework.boot</groupId>
    				<artifactId>spring-boot-starter-web</artifactId>
    			</dependency>
    		</dependencies>
    6 application.yml为:
    #Dubbo 服务消费者配置	
    server:
        port: 8081
    spring:
        dubbo:
            application: #应用配置,用于配置当前应用信息,不管该应用是提供者还是消费者。
    	    name: consumer
            registry: #注册中心配置,用于配置连接注册中心相关信息。
    	    address: zookeeper://xxx.xxx.xxx.xxx:2181
            protocol:     #协议配置,用于配置提供服务的协议信息,协议由提供方指定,消费方被动接受。
    	    name: dubbo
    	    port: 20880
            scan: com.laowang.dubbo #服务暴露与发现消费所在的package

         PS:请大家注意yml语法,这里编辑器无法正常显示格式。很郁闷。

                7 先启动provider项目,然后可以观察dubbo管控台是否有服务已经注册到zookeeper上:


    8 然后启动consumer项目,访问刚刚的服务即可,这样,一个简单的SpringBoot+Dubbo框架就搭好了。

                    目前的项目结构是这样的:

                            parent:

                            

                            provider:

                            

                            consumer:

                            

    (第一次写这种博文,希望大家多提意见~~~下一节将继续整合SpringBoot+Dubbo+MyBatisplus+Oracle吐舌头
  • 相关阅读:
    常用安卓开发技巧汇总
    安卓开发30:AsyncTask的用法
    JBoss AS7 快速配置
    抓包 把笔记本改造成无线路由器 —— 手机抓包牛刀小试
    Android系统手机端抓包方法
    ApkTool反编译apk,去除广告或者汉化后重新打包apk,并签名
    Android中如何像 360 一样优雅的杀死后台Service而不启动
    android service 的各种用法(IPC、AIDL)
    Android shell 下 busybox,clear,tcpdump、、众多命令的移植
    Servlet3.0中Servlet的使用
  • 原文地址:https://www.cnblogs.com/laowangc/p/8869974.html
Copyright © 2011-2022 走看看