记录一下 搭建springboot,springCloud,springCloudAlibaba,nacos

1,首先创建一个空项目 里面 有两个服务 一个提供者 一个调用者

 2,父工程的使用依赖  以及springBoot的父依赖

    // springboot父工程
    <parent>
        <artifactId>spring-boot-starter-parent</artifactId>
        <groupId>org.springframework.boot</groupId>
        <version>2.3.12.RELEASE</version>
    </parent>

    <groupId>com.yh</groupId>
    <artifactId>day0804</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>day_user</module>
        <module>day_application</module>
    </modules>

    <name>day0804</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>
    // 一些配置信息和版本
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <!--        三个框架版本-->
        <org.boot.service>2.3.12.RELEASE</org.boot.service>
        <org.cloud.service>Hoxton.SR12</org.cloud.service>
        <org.cloudali.service>2.2.7.RELEASE</org.cloudali.service>
        <!--        lombok版本-->
        <org.lombok.version>1.18.20</org.lombok.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!--      boot依赖-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${org.boot.service}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--      cloud依赖-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${org.cloud.service}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--      alibaba依赖-->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${org.cloudali.service}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

然后在服务提供者(day_user_service)引用依赖

 

 pom依赖

  // 一些基本配置
 <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>
// 构建者 有时候自动会有
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
// nacos发现注册服务
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
// nacos配置中心 使用bootstrap.yaml
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
// dubbo服务
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-dubbo</artifactId>
        </dependency>
// 有时候dubbo服务引入有可能会出现某些问题 引入这个依赖
        <dependency>
            <groupId>com.alibaba.spring</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>1.0.11</version>
        </dependency>
// web服务
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
// boot启动器
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
// 过滤logging 会出版本冲突问题所以移除
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
// mybatis启动
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.0</version>
        </dependency>
// jdbc驱动
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
// druid连接池
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.2.16</version>
        </dependency>
// mysql驱动器
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.49</version>
        </dependency>
// 将自己的配置你自己创建的配置类生成元数据信息
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
// 是一个spring提供的监控模块
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
// 测试
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
// lombok 
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${org.lombok.version}</version>
        </dependency>
// 用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端/服务器
//编程工具包,并且它支持 HTTP 协议最新的版本和建议
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <version>4.4.1</version>
            <artifactId>httpcore</artifactId>
        </dependency>
// 分页工具
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.2.1</version>
        </dependency>
        <dependency>
            <groupId>com.yh</groupId>
            <artifactId>day_user_api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    // vo dto 服务层的格式转换
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct-jdk8</artifactId>
            <version>1.3.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct-processor</artifactId>
            <version>1.3.0.Final</version>
        </dependency>
    </dependencies>

boorstrap配置信息

server:
  port: 1996
spring:
  application:
    name: user-service
  #    nacos
  cloud:
    nacos:
      config:
        cluster-name: DEFAULT
        server-addr: 127.0.0.1:8848
  #    数据源
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    password: root123
    username: root
    url: jdbc:mysql://127.0.0.1:3306/crud?useSSL=false

# dubbo配置
dubbo:
  scan:
    # dubbo 服务扫描基准包
    base-packages: com.yh
  protocol:
    # dubbo 协议
    name: dubbo
    port: 20994
  registry:
    address: nacos://127.0.0.1:8848
  application:
    qos:
      port: 22240 # dubbo qos端口配置  命令行注入
  consumer:
    check: false
    timeout: 90000
    retries: -1
#    mybatis
mybatis-plus:
  type-aliases-package: com.yh.model
  mapper-locations: classpath:mapper/*.xml

调用者(day_application)配置及依赖

 

    <dependencies>
<!--        web-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
<!--        boot-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <!--        配置中心-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
        <!--        注册发现服务-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <!--        dobbo-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-dubbo</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.spring</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>1.0.11</version>
        </dependency>
        <dependency>
            <groupId>com.yh</groupId>
            <artifactId>day_user_api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.47</version>
        </dependency>
    </dependencies>

bootstrap

server:
  port: 10000
spring:
  application:
    name: user-app
  #    nacos
  cloud:
    nacos:
      config:
        cluster-name: DEFAULT
        server-addr: 127.0.0.1:8848

# dubbo配置
dubbo:
  scan:
    # dubbo 服务扫描基准包
    base-packages: com.yh
  protocol:
    # dubbo 协议
    name: dubbo
    port: 20995
  registry:
    address: nacos://127.0.0.1:8848
  application:
    qos:
      port: 22240 # dubbo qos端口配置  命令行注入
  consumer:
    check: false
    timeout: 90000
    retries: -1

简单配置就这些 根据需求不断地增加迭代 不过是要注意版本之间的兼容性

 
posted @ 2023-08-06 13:23  Smile☆  阅读(38)  评论(0编辑  收藏  举报