SpringCloud框架开发教程

本文章是根据B站UP主尚硅谷周阳老师教学视频进行练习,会持续更新
视频链接:https://www.bilibili.com/vide...

SpringCloud=分布式微服务架构的一站式解决方案,是多种微服务架构落地技术的集合体,俗称微服务全家桶

SpringBoot是一种服务开发技术

服务注册与发现:EUREKA

服务负载均衡与调用:NETFLIX OSS RIBBON

服务负载与调用:NETTFLIX

服务熔断降级:HYSTRIX

服务网关:Zuul

服务分布式配置:SpringCloud Config

服务开发:SpingBoot

1、新建Maven项目,删除Src文件,此项目作为聚合工程的父工程使用
POM文件


xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/m...d">
4.0.0
com.springcloud
cloud2021
1.0-SNAPSHOT
pom
Maven

http://maven.apache.org/
2001
website
scp://webhost.company.com/www/website



UTF-8
1.8
1.8
4.12
1.2.17
1.16.18
5.1.47
1.1.16
1.3.0





org.springframework.boot
spring-boot-dependencies
2.2.2.RELEASE
pom
import


org.springframework.cloud
spring-cloud-dependencies
Hoxton.SR1
pom
import


com.alibaba.cloud
spring-cloud-alibaba-dependencies
2.1.0.RELEASE
pom
import
mysql
mysql-connector-java
${mysql.version}
com.alibaba
druid
${druid.version}
org.mybatis.spring.boot
mybatis-spring-boot-starter
${mybatis.spring.boot.version}
junit
junit
${junit.version}
org.projectlombok
lombok
${lombok.version}
true

org.springframework.boot
spring-boot-maven-plugin
true
true

2、数据库建表

  1. CREATE DATABASE /!32312 IF NOT EXISTS/cloud /!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci /;
  1. USE cloud;
  2. /Table structure for table payment /
  3. DROP TABLE IF EXISTS payment;
  4. CREATE TABLE payment (
  5. id bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  6. serial varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
  7. PRIMARY KEY (id)
  8. ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  9. /Data for the table payment /
  10. insert  into payment(id,serial) values (1,'尚硅谷'),(2,'alibaba'),(3,'京东'),(4,'头条');

3、在父工程内新建子模块
POM如下:


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/m...d">
cloud2021
com.springcloud
1.0-SNAPSHOT
4.0.0
cloud-provider-payment8001
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-actuator
org.mybatis.spring.boot
mybatis-spring-boot-starter
com.alibaba
druid-spring-boot-starter
1.1.10


mysql
mysql-connector-java
org.springframework.boot
spring-boot-starter-jdbc
org.springframework.boot
spring-boot-devtools
runtime
true
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-test
test

4、在子模块中添加application.yml文件并进行配置

server:
port: 8001
spring:
application:
name: cloud-provider-service

datasource:

type: com.alibaba.druid.pool.DruidDataSource

driver-class-name: org.gjt.mm.mysql.Driver
url: jdbc:mysql://localhost:3306/cloud2021?useUnicode=true&characterEncoding-utr-8&useSSL=false

username: root
password: root

mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.springcloud.entities

你可能感兴趣的:(mysql,java,springboot)