SpringCloud--14使用Spring Cloud 构建微服务综合案例2(搭建工程)

1.zipkin-service

zipkin-server,它的主要作用使用ZipkinServer 的功能,收集调用数据,并展示,在spring Cloud更加高版本的时候,已经不需要自己构建Zipkin Server了,只需要下载jar即可。

下载jar包下来启动,访问:http://localhost:9411/zipkin/

2.monitoring-service

  monitoring-service工程集成了TurBbine组件,用于聚合多个Hystrix Dashboard,本工程中,user-service和blog-service集成了Hystrix Dashboard,monitoring-service就是将这两个工程聚合在一起。Hystrix Dashboard是监控Hystrix熔断器的组件,使用Fegin做远程调用的时候,Fegin是默认集成了Hystrix的。

工程的配置文件存放在config-server中。

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.wx</groupId>
        <artifactId>SpringCloudInAction</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.wx</groupId>
    <artifactId>monitoring-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>monitoring-service</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <!--<dependency>-->
            <!--<groupId>org.springframework.cloud</groupId>-->
            <!--<artifactId>spring-cloud-starter-turbine</artifactId>-->
        <!--</dependency>-->

        <!--<dependency>-->
            <!--<groupId>org.springframework.boot</groupId>-->
            <!--<artifactId>spring-boot-starter-actuator</artifactId>-->
        <!--</dependency>-->

        <!--&lt;!&ndash;hystrix-dashboard&ndash;&gt;-->
        <!--<dependency>-->
            <!--<groupId>org.springframework.cloud</groupId>-->
            <!--<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>-->
        <!--</dependency>-->
        <!--&lt;!&ndash;hystrix &ndash;&gt;-->
        <!--<dependency>-->
            <!--<groupId>org.springframework.cloud</groupId>-->
            <!--<artifactId>spring-cloud-starter-hystrix</artifactId>-->
        <!--</dependency>-->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</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-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
        </dependency>
    </dependencies>

    <build>
        <finalName>app</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

 boorstrap,yml

spring:
  application:
    name: monitor-service
  cloud:
    config:
      uri: http://localhost:8001
      fail-fast: true
  profiles:
      active: pro

application.yml:

server:
  port: 8002
security.basic.enabled: false
turbine:
  aggregator:
    clusterConfig: default
  appConfig: user-service , blog-service
  clusterNameExpression: new String("default")

management:
  security:
    enabled: false

  启动类上打上注解:

  

3.uaa-service

   1.浏览器访问user-service的登陆接口,登陆接口是不设权限的,user-service会查询数据库验证用户名和密码。

   2.验证无误后,通过Fegin远程调用uaa-service获取Token,需要传入一个clientId,username,pwd,clientId要和uaa服务设置的clientId是一样的。

   3.uaa-service接收到请求之后,会判断传入的参数clientId,用户名和密码的正确性。

   4.判断上一步请求参数准确无误后,uaa-service根据配置的策略返回JWT给user-service,JWT是通过RSA加密的,他包含了用户名,权限信息,和过期时间。

   5.user-service获取JWT以后,连同用户信息一起返回给浏览器。

   6.当浏览器需要访问有权限认证的资源服务时,需要在请求的Header加上Token,

   7.资源服务通过通过SpringMVC的拦截器对请求进行拦截,将Header中的Token取出来,用公钥解密Token,解密之后就能得到用户信息和权限的信息,从而进行权限认证。

  8.当有权限就会访问资源服务器的资源,没有权限就GG。

 

  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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.wx</groupId>
        <artifactId>SpringCloudInAction</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.wx</groupId>
    <artifactId>uaa-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>uaa-service</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- 配置-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

    </dependencies>

    <build>
        <finalName>app</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

  bootstrap.yml:

spring:
  application:
    name: uaa-service
  cloud:
    config:
      uri: http://localhost:8001
      fail-fast: true
  profiles:
      active: pro

 application.yml:

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8000/eureka/
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/sys-user?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
    username: root
    password: 133309
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
server:
  port: 9999

 注解:

当然还有Security和OAuth2的配置,这里就不展示了。

4.构建gateway-service工程

  集成了Zuul组件,有路由转发过滤和鉴权的功能,这里只用到了路由转发。

   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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.wx</groupId>
        <artifactId>SpringCloudInAction</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.wx</groupId>
    <artifactId>gateway-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>gateway-service</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
        <!-- 配置-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

 bootstrap.yml依赖:

spring:
  application:
    name: gateway-service
  cloud:
    config:
      uri: http://localhost:8001
      fail-fast: true
  profiles:
    active: pro

application,yml:

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 20000

ribbon:
  ReadTimeout: 20000
  ConnectTimeout: 20000

zuul:
  host:
    connect-timeout-millis: 20000
    socket-timeout-millis: 20000

  routes:
    user-service:
      path: /userapi/**
      serviceId: user-service
      sensitiveHeaders:

    blog-service:
      path: /blogapi/**
      serviceId: blog-service
      sensitiveHeaders:

server:
  port: 8080

 注解:

 

 5.admin-service工程

 集成了spring boot admin server 该工程需要向Eureka服务器注册,便于获取注册表信息,然后admin server会请求注册表信息中服务的Actuator的API接口,从而获取这些服务的监控信息。所以所以所有向eureka server注册的服务都要加上Actuator的起步依赖。如果Actuator开启了安全验证需要将安全验证关掉。

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.wx</groupId>
        <artifactId>SpringCloudInAction</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.wx</groupId>
    <artifactId>admin-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>admin-service</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- 配置依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <!--spring cloud admin server ui-->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui</artifactId>
            <version>1.5.1</version>
        </dependency>

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui-turbine</artifactId>
            <version>1.5.1</version>
        </dependency>

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui-hystrix</artifactId>
            <version>1.5.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-turbine</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!--hystrix-dashboard-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
        </dependency>
        <!--&lt;!&ndash;hystrix &ndash;&gt;-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui-login</artifactId>
            <version>1.5.0</version>
        </dependency>

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui-activiti</artifactId>
            <version>1.5.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

 bootstrap.yml:

spring:
  application:
    name: admin-service
  cloud:
    config:
      uri: http://localhost:8001
      fail-fast: true
  profiles:
    active: pro

 application.yml:

 集成了Security,并且配置了Security

server:
  port: 8003
spring:
  application:
    name: admin-client
  security:
    user:
      name: "admin"
      password: "admin"
eureka:
  instance:
    leaseRenewalIntervalInSeconds: 10
    health-check-url-path: /actuator/health
    metadata-map:
       user.name: ${spring.security.user.name}
       user.password: ${spring.security.user.password}
  client:
    registryFetchIntervalSeconds: 5
    service-url:
      defaultZone: ${EUREKA_SERVICE_URL:http://peer1:8000}/eureka/
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS

logging:
  file: "logs/admin-service-pro.log"

  注解:
 

6.user-service工程

 user-service具有以下校色或能力

 作为eureka-client,向eureka-server服务注册中心注册

 作为Config-client,从config-server读取配置文件

  作为ziplin-client,上传链路追踪数据给Zipkin Server

 作为作为Spring Boot Admin Client,SPringl Boot Admin Server 会定期检查user-service的健康状态,

 作为资源服务器,user-service的大部分资源需要鉴权才能访问。

 使用Fegin作为声明式调用框架,并启动了Hystrix熔断器,集成了Hystrix Dashboard组件

 集成了在线API文档框架

 使用Mysql作为数据库

 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.wx</groupId>
        <artifactId>SpringCloudInAction</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.wx</groupId>
    <artifactId>user-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>user-service</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.wx</groupId>
            <artifactId>common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>

        <!-- 配置-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
            <version>1.4.5.RELEASE</version>
        </dependency>

        <!-- 开启web-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- 开启feign-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
            <version>1.4.5.RELEASE</version>
        </dependency>

        <!-- dashboard -->
        <!-- actuator-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>1.4.5.RELEASE</version>
        </dependency>
        <!--hystrix-dashboard-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <!--断路器监控依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
            <version>1.4.5.RELEASE</version>
        </dependency>

        <!-- zipkin-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
            <version>2.0.3.RELEASE</version>
        </dependency>

        <!--swagger-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>
        <!--database-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!--security-->


        <!-- mq -->
        <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit</artifactId>
            <version>2.0.3.RELEASE</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

  bootstrap.yml文件

spring:
  application:
    name: user-service
  cloud:
    config:
      uri: http://localhost:8000
      fail-fast: true
  profiles:
    active: pro

 application.yml:

server:
  port: 8004


spring:
  zipkin:
    base-url: http://localhost:9411

#  rabbitmq:
#    host: localhost
#    port: 5672
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/sys-user?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
    username: root
    password: 133309
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true

  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest
    publisher-confirms: true
    virtual-host: /

foo: foo version 1

  注解:

  

  7.log-service工程

  log-service为日志收集的服务,该服务只收集一些比较重要的日志,并进行持久化,持久化的数据库为Mysql,在日志服务架构中,user-service和blog-service发送日志消息给RabbitMQ服务器,log-service通过监听RabbitMQ服务器获取日志,并通过JPA保存日志信息到MySQL服务器,在业务服务的Controller中,在方法上加注解,通过AOP进行拦截注解,然后进行日志的提取,提取出的信息包括Controller的方法名字,参数,操作人,IP等等。

  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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.wx</groupId>
        <artifactId>SpringCloudInAction</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.wx</groupId>
    <artifactId>log-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>log-service</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <dependency>
            <groupId>com.wx</groupId>
            <artifactId>common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!-- 配置-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <!-- actuator-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!--database-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!-- mq -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

 bootstrap.yml文件:
 

spring:
  application:
    name: logger-service
  cloud:
    config:
      uri: http://localhost:8001
      fail-fast: true
  profiles:
    active: pro

 application.yml文件:

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/sys-log?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
    username: root
    password: 133309
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true

  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest
    publisher-confirms: true
    virtual-host: /

server:
  port: 9997

  注解:

 

  7.blog-service工程

 

  ok 准备数据库:

  三个库,五张表 

启动工程:

依次启动eureka-server,config-server,zipkin-service,再启动其他的服务。

启动zipkin:

java -jar zipkin-server-2.2.0-exec.jar --zipkin.collector.rabbitmq.addresses=localhost:5672 --zipkin.collector.rabbitmq.username=guest --zipkin.collector.rabbitmq.password=guest

访问swagger:http://127.0.0.1:8080/swagger-ui.html#/

访问rabbitMQ:http://localhost:15672/#/queues

访问zipkin:http://localhost:9411/zipkin/

 注册一个用户:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"password":"123456","username":"wx"}' 'http://localhost:8080/userapi/user/registry'

  注册成功:

登陆:

curl -X POST --header 'Content-Type: application/json' --header 'Accept:application/json' 'http://localhost:8080/userapi/user/login?username=admin&password=admin'

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

时空恋旅人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值