我是靠谱客的博主 美满刺猬,最近开发中收集的这篇文章主要介绍尚硅谷SpringCloud2020简单学习记录(个人用)1-8集,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

版本选择:

Cloud:Hoxton.SR1

Boot:2.2.2.RELEASE

CLOUD ALIBABA 2.1.0.RELEASE

JAVA JAVA8

MAVEN 3.5以上

MYSQL 5.7以上

服务注册中心:

Eureka已被抛弃,但要学,一切的基础

Zookeeper

Consul

Nacos 重点

服务调用:

Ribbon

LoadBalancer

Feign 被抛弃

OpenFeign

服务降级:

Hystrix已被抛弃

Resilience4j

Sentinel

服务网关:

Zuul已被抛弃

Zuul2胎死腹中

Gateway

服务配置:

Config被抛弃

Nacos

服务总线:

Bus被抛弃了

Nacos

订单-支付模块微服务:

约定>配置>编码

总父工程

创建工程步骤:

1新建工程

2聚合总父工程名

3.Maven选版本

4.工程名字

选择maven工程,sdk选1.8,根据版本选archetypes:maven-archetype-site,接着往下建即可

5.字符编码

进入settings,editor,fileEncodings中选择Encoding都为UTF-8,Properties Files那里记得✔

6.注解生效激活

Settings,build,execution,deployment,compiler,annotation processors中选择default,然后enable annotation processing✔

7.java版本选8

Settings,build,execution,deployment,compiler,javacompiler,module中选8

8.File Type过滤(可做可不做)

总父工程POM.XML:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.xs.springColud</groupId><!--自己的groupId-->

  <artifactId>cloud2020</artifactId><!--自己的artifactId-->

  <version>1.0-SNAPSHOT</version>

   

  <packaging>pom</packaging>

  <!-- packaging pom 总工程-->

  <!--统一管理jar包版本-->

  <properties>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <maven.compiler.source>8</maven.compiler.source>

    <maven.compiler.target>8</maven.compiler.target>

    <junit.version>4.12</junit.version>

    <lombok.version>1.18.10</lombok.version>

    <log4j.version>1.2.17</log4j.version>

    <mysql.version>5.1.47</mysql.version>

    <druid.version>1.1.16</druid.version>

    <mybatis.spring.boot.version>1.3.0</mybatis.spring.boot.version>

  </properties>

  <!--子模块继承之后,提供作用:锁定版本+子module不用写groupId和version-->

  <dependencyManagement><!--定义规范,但不导入-->

  <dependencies>

  <dependency>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-project-info-reports-plugin</artifactId>

    <version>3.0.0</version>

  </dependency>

  <!--spring boot 2.2.2-->

  <dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-dependencies</artifactId>

    <version>2.2.2.RELEASE</version>

    <type>pom</type>

    <scope>import</scope>

  </dependency>

  <!--spring cloud Hoxton.SR1-->

  <dependency>

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-dependencies</artifactId>

    <version>Hoxton.SR1</version>

    <type>pom</type>

    <scope>import</scope>

  </dependency>

  <!--spring cloud 阿里巴巴-->

  <dependency>

    <groupId>com.alibaba.cloud</groupId>

    <artifactId>spring-cloud-alibaba-dependencies</artifactId>

    <version>2.1.0.RELEASE</version>

    <type>pom</type>

    <scope>import</scope>

  </dependency>

  <!--mysql-->

  <dependency>

    <groupId>mysql</groupId>

    <artifactId>mysql-connector-java</artifactId>

    <version>${mysql.version}</version>

    <scope>runtime</scope>

  </dependency>

  <!-- druid-->

  <dependency>

    <groupId>com.alibaba</groupId>

    <artifactId>druid</artifactId>

    <version>${druid.version}</version>

  </dependency>

    <!--mybatis-->

    <dependency>

      <groupId>org.mybatis.spring.boot</groupId>

      <artifactId>mybatis-spring-boot-starter</artifactId>

      <version>${mybatis.spring.boot.version}</version>

    </dependency>

    <!--junit-->

    <dependency>

      <groupId>junit</groupId>

      <artifactId>junit</artifactId>

      <version>${junit.version}</version>

    </dependency>

    <!--log4j-->

    <dependency>

      <groupId>log4j</groupId>

      <artifactId>log4j</artifactId>

      <version>${log4j.version}</version>

    </dependency>

  </dependencies>

  </dependencyManagement>

   <!--热启动插件-->

  <build>

    <plugins>

      <plugin>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-maven-plugin</artifactId>

        <configuration>

          <fork>true</fork>

          <addResources>true</addResources>

        </configuration>

      </plugin>

    </plugins>

  </build>

</project>

DependencyManagement元素常用在父pom里,可以让所有子项目中的依赖不用显示列出版本号,会自动使用父pom中DependencyManagement指定的版本号

Order模块:客户端消费者80

Payment模块:微服务提供者8001

微服务模块:

1建module

选maven项目,这次不要模板,sdk选1.8,下一步继续,模块名cloud-provider-payment8001,新建module

2改pom

然后去主pom.XML中把modules块改到packaging下面

在cloud-provider-payment8001中的pom.xml中添加以下内容:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <parent>

        <artifactId>cloud2020</artifactId>

        <groupId>com.xs.springcloud</groupId>

        <version>1.0-SNAPSHOT</version>

    </parent>

    <modelVersion>4.0.0</modelVersion>



    <artifactId>cloud-provider-payment8001</artifactId>



    <dependencies>

        <!-- 服务注册中心的客户端端 eureka-client -->

        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server -->

<!--        <dependency>-->

<!--            <groupId>org.springframework.cloud</groupId>-->

<!--            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>-->

<!--        </dependency>-->



<!--        &lt;!&ndash; 引入自己定义的api通用包 &ndash;&gt;-->

<!--        <dependency>-->

<!--            <groupId>com.atguigu.springcloud</groupId>-->

<!--            <artifactId>cloud-api-commons</artifactId>-->

<!--            <version>${project.version}</version>-->

<!--            <scope>compile</scope>-->

<!--        </dependency>-->



        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>



        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-actuator</artifactId>

        </dependency>



        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->

        <dependency>

            <groupId>org.mybatis.spring.boot</groupId>

            <artifactId>mybatis-spring-boot-starter</artifactId>

        </dependency>



        <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->

        <dependency>

            <groupId>com.alibaba</groupId>

            <artifactId>druid-spring-boot-starter</artifactId>

            <version>1.2.8</version>

        </dependency>

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->

        <dependency>

            <groupId>mysql</groupId>

            <artifactId>mysql-connector-java</artifactId>

        </dependency>



        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-jdbc</artifactId>

        </dependency>



<!--         https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools-->

                <dependency>

                    <groupId>org.springframework.boot</groupId>

                    <artifactId>spring-boot-devtools</artifactId>

                    <scope>runtime</scope>

                    <optional>true</optional>

                </dependency>



        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->

        <dependency>

            <groupId>org.projectlombok</groupId>

            <artifactId>lombok</artifactId>

            <optional>true</optional>

        </dependency>



        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-test</artifactId>

            <scope>test</scope>

        </dependency>



        <!--包含了sleuth+zipkin-->

<!--        <dependency>-->

<!--            <groupId>org.springframework.cloud</groupId>-->

<!--            <artifactId>spring-cloud-starter-zipkin</artifactId>-->

<!--        </dependency>-->



    </dependencies>



</project>

注释内容是之后要加的

3写yml

server:

  port: 8001



spring:

  application:

    name: cloud-payment-service



  datasource:

    type: com.alibaba.druid.pool.DruidDataSource

    driver-class-name: org.gjt.mm.mysql.Driver

    url: jdbc:mysql://localhost:3306/cloud2020?useUnicode=true&characterEncoding=utf-8&useSSL=false

    username: root

    password: root



mybatis:

  mapper-locations: classpath:mapper/*.xml

  type-aliases-package: com.xs.springcloud.entities

后续还会加入新内容

4主启动

在java文件中创建com/xs/springcloud/PaymentMain8001.java

package com.xs.springcloud;



import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;



@SpringBootApplication

public class PaymentMain8001 {

    public static void main(String[] args) {

        SpringApplication.run(PaymentMain8001.class,args);

    }

}

以上为1-8集的内容

最后

以上就是美满刺猬为你收集整理的尚硅谷SpringCloud2020简单学习记录(个人用)1-8集的全部内容,希望文章能够帮你解决尚硅谷SpringCloud2020简单学习记录(个人用)1-8集所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(84)

评论列表共有 0 条评论

立即
投稿
返回
顶部