springcloud五大组件,透过根源从而探究红黑树的本质

3、安装Redis

springcloud五大组件,透过根源从而探究红黑树的本质

二、创建父工程


我觉得主要是pom文件

<?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”>

4.0.0

com.guor

GooReeyProject

1.0-SNAPSHOT

01common

02gateway

<system.version>1.0.0</system.version>

<system.ip>127.0.0.1</system.ip>

<system.sport>808</system.sport>

<system.mode>http</system.mode>

<java.version>1.8</java.version>

<spring-cloud.version>Greenwich.SR1</spring-cloud.version>

true

<nacos.version>0.2.2.RELEASE</nacos.version>

pom

GooReeyProject

This is parent project

org.springframework.boot

spring-boot-starter-parent

2.1.4.RELEASE

org.springframework.boot

spring-boot-starter-test

test

org.projectlombok

lombok

provided

commons-lang

commons-lang

2.6

com.github.pagehelper

pagehelper-spring-boot-starter

1.2.5

org.springframework.cloud

spring-cloud-starter-alibaba-nacos-discovery

com.alibaba

druid

1.1.23

org.springframework.cloud

spring-cloud-starter-alibaba-nacos-config

0.2.1.RELEASE

org.springframework.cloud

spring-cloud-dependencies

${spring-cloud.version}

pom

import

org.springframework.cloud

spring-cloud-alibaba-dependencies

${nacos.version}

pom

import

src/main/re

《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》

【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享

sources

**/.

src/main/resources

**/*.yml

true

src/main/java

**/*.xml

三、创建gateway子工程


1、pom文件

<?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”>

GooReeyProject

com.guor

1.0-SNAPSHOT

4.0.0

02gateway

org.mybatis.spring.boot

mybatis-spring-boot-starter

2.0.1

org.springframework.cloud

spring-cloud-starter-gateway

org.springframework.cloud

spring-cloud-starter-netflix-hystrix

org.springframework.cloud

spring-cloud-starter-alibaba-nacos-config

com.alibaba.cloud

spring-cloud-starter-alibaba-nacos-discovery

org.springframework.cloud

spring-cloud-starter-netflix-ribbon

gateway-${system.version}

2、配置文件

spring:

application:

name: gateway

cloud:

nacos:

discovery:

server-addr: 127.0.0.1:8848

config:

server-addr: 127.0.0.1:8848

file-extension: yml

ext-config:

  • data-id: datasource-share-config.yml

group: SHARE_GROUP

refresh: true

  • data-id: log-share-config.yml

group: SHARE_GROUP

refresh: true

springcloud五大组件,透过根源从而探究红黑树的本质

(1)gateway.yml

server:

port: 8080

spring:

application:

name: gateway

version: 1.0.0

cloud:

gateway:

discovery:

locator:

enabled: true

lowerCaseServiceId: true

filters:

  • StripPrefix=1

routes:

  • id: management

uri: lb:management # 服务端 service_id

predicates:

  • Path=/management/**

filters:

  • name: Hystrix

args:

name: fallbackcmd

fallbackUri: forward:/defaultFallback

  • id: demo

uri: lb://demo

predicates:

  • Path=/demo/**

hystrix:

command:

default:

execution:

isolation:

strategy: SEMAPHORE

thread:

timeoutInMilliseconds: 1500

(2)datasource-share-config.yml

spring:

datasource:

url: jdbc:mysql://localhost:3306/blue?serverTimezone=UTC

driverClassName: com.mysql.cj.jdbc.Driver

username: root

password: root

mybatis:

typeAliasesPackage: com.guor.*.bean.**

mapperLocations: classpath*:/com/guor//dao/mapping/*Mapper.xml

configuration:

map-underscore-to-camel-case: true

(3)log-share-config.yml

logging:

path: logs

level:

root: info

com.alibaba.nacos.client.naming: warn

file:

max-size: 20MB

max-history: 30

pattern:

file: “%d{${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:%5p} P I D : − − − − [ {PID:- } --- [%15.15t] %-40.40logger{39} [%5.5line] : %m%n PID:−−−−[{LOG_EXCEPTION_CONVERSION_WORD:%wEx}”

console: “%d{KaTeX parse error: Expected 'EOF', got '}' at position 49: …d HH:mm:ss.SSS}}̲ %clr({LOG_LEVEL_PATTERN:%5p}) %clr( P I D : − ) m a g e n t a − − − {PID:- }){magenta} --- %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr([%5.5line]){cyan} : %m%n PID:−)magenta−−−{LOG_EXCEPTION_CONVERSION_WORD:%wEx}”

3、启动类

package com.guor;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

import org.springframework.cloud.context.config.annotation.RefreshScope;

import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

@EnableDiscoveryClient

@EnableScheduling

@RefreshScope

public class GatewayApplication {

public static void main(String[] args) {

SpringApplication.run(GatewayApplication.class, args);

System.out.println(“hello world”);

}

}

springcloud五大组件,透过根源从而探究红黑树的本质

四、创建management管理模块


1、pom文件

<?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”>

GooReeyProject

com.guor

1.0-SNAPSHOT

4.0.0

03management

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

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

org.springframework.boot

spring-boot-starter-web

org.mybatis.spring.boot

mybatis-spring-boot-starter

2.0.1

org.springframework.cloud

spring-cloud-starter-alibaba-nacos-config

mysql

mysql-connector-java

org.springframework.boot

spring-boot-starter-jdbc

management-${system.version}

2、配置文件

spring:

application:

name: management

cloud:

nacos:

discovery:

server-addr: 127.0.0.1:8848

config:

server-addr: 127.0.0.1:8848

file-extension: yml

ext-config:

  • data-id: datasource-share-config.yml

group: SHARE_GROUP

refresh: true

  • data-id: log-share-config.yml

group: SHARE_GROUP

refresh: true

server:

port: 8081

spring:

application:

name: management

version: 1.0.0

mvc:

static-path-pattern: /management/**

resources:

static-locations:

  • file:…/…/web/management

  • file:…/…/web/common

3、启动类

package com.guor;

import org.mybatis.spring.annotation.MapperScan;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

import org.springframework.cloud.context.config.annotation.RefreshScope;

@EnableDiscoveryClient

@SpringBootApplication(scanBasePackages = “com.guor”)

@MapperScan(“com.guor.management.dao”)

@RefreshScope

public class ManagementApplication {

public static void main(String[] args) {

SpringApplication.run(ManagementApplication.class, args);

}

}

springcloud五大组件,透过根源从而探究红黑树的本质

五、整合mybatis


1、user表设计

数据库选择的是最常用的MySQL

CREATE TABLE user (

user_id int(10) unsigned NOT NULL AUTO_INCREMENT,

username varchar(100) NOT NULL,

上一篇:SpringCloud微服务实战——搭建企业级开发框架(三十四):SpringCloud + Docker + k8s实现微服务集群打包部署-打包配置


下一篇:java学习路线