一篇打通微服务架构,Nacos + Gateway + Redis + MySQL + Docker( 二 )

三、创建gateway子工程1、pom文件<?xml versinotallow="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>NZBCProject</artifactId><groupId>com.guor</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>02gateway</artifactId><dependencies><dependency><groupId>org.MyBatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.0.1</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter.NETflix-hystrix</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId><exclusions><exclusion><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-ribbon</artifactId></exclusion></exclusions></dependency></dependencies></dependencyManagement><build><finalName>gateway-${system.version}</finalName></build></project>2、配置文件spring:Application:name: gatewaycloud:nacos:discovery:server-addr: 127.0.0.1:8848config:server-addr: 127.0.0.1:8848file-extension: ymlext-config:- data-id: datasource-share-config.ymlgroup: SHARE_GROUPrefresh: true- data-id: log-share-config.ymlgroup: SHARE_GROUPrefresh: true

一篇打通微服务架构,Nacos + Gateway + Redis + MySQL + Docker

文章插图
(1)gateway.ymlserver:port: 8080spring:application:name: gatewayversion: 1.0.0cloud:gateway:discovery:locator:enabled: truelowerCaseServiceId: truefilters:- StripPrefix=1routes:- id: managementuri: lb:management# 服务端 service_idpredicates:- Path=/management/**filters:- name: Hystrixargs:name: fallbackcmdfallbackUri: forward:/defaultFallback- id: demouri: lb://demopredicates:- Path=/demo/**hystrix:command:default:execution:isolation:strategy: SEMAPHOREthread:timeoutInMilliseconds: 1500(2)datasource-share-config.yml spring:datasource:url: jdbc:mysql://localhost:3306/blue?serverTimeznotallow=UTCdriverClassName: com.mysql.cj.jdbc.Driverusername: rootpassword: rootmybatis:typeAliasesPackage: com.guor.*.bean.**mapperLocations: classpath*:**/com/guor/**/dao/mapping/*Mapper.xmlconfiguration:map-underscore-to-camel-case: true(3)log-share-config.yml logging:path: logslevel:root: infocom.alibaba.nacos.client.naming: warnfile:max-size: 20MBmax-history: 30pattern:file: "%d{${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:%5p} ${PID:- } --- [%15.15t] %-40.40logger{39} [%5.5line] : %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}"console: "%d{${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}} %clr(${LOG_LEVEL_PATTERN:%5p}) %clr(${PID:- }){magenta} --- %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr([%5.5line]){cyan} : %m%n${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@RefreshScopepublic class GatewayApplication {public static void main(String[] args) {SpringApplication.run(GatewayApplication.class, args);System.out.println("hello world");}} 
一篇打通微服务架构,Nacos + Gateway + Redis + MySQL + Docker

文章插图
 
四、创建management管理模块1、pom文件<?xml versinotallow="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>NZBCProject</artifactId><groupId>com.guor</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>03management</artifactId><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.0.1</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><!--MySQL依赖 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency></dependencies><build><finalName>management-${system.version}</finalName></build></project>


推荐阅读