• Spring cloud:支付微服务-服务注册


    环境

    1. spring cloud Edgware.SR6
    2. jdk 7
    3. sts 4.6.0
    4. mysql 5.7

    背景

    将支付微服务注册到 eureka 中,为了简单,eureka 只启动了一台,即单机版。

    搭建步骤

    增加 pom.xml 依赖

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

    第一个节点

    sserver:
      port: 4420
    
    spring:
      application:
        name: payment
    
      datasource:
        url: jdbc:mysql://localhost/spring_cloud_payment?useUnicode=true&characterEncoding=utf-8&useSSL=false
        driver-class-name: com.mysql.jdbc.Driver
        username: root
        password: jiangbo
    
    eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:8761/eureka/
    

    第二个节点

    server:
      port: 4421
    
    spring:
      application:
        name: payment
    
      datasource:
        url: jdbc:mysql://localhost/spring_cloud_payment?useUnicode=true&characterEncoding=utf-8&useSSL=false
        driver-class-name: com.mysql.jdbc.Driver
        username: root
        password: jiangbo
    
    eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:8761/eureka/
    

    第三个节点

    server:
      port: 4422
    
    spring:
      application:
        name: payment
    
      datasource:
        url: jdbc:mysql://localhost/spring_cloud_payment?useUnicode=true&characterEncoding=utf-8&useSSL=false
        driver-class-name: com.mysql.jdbc.Driver
        username: root
        password: jiangbo
    
    eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:8761/eureka/
    

    启动类

    package jiangbo.springcloud;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    
    @SpringBootApplication
    @EnableEurekaClient
    public class JiangBoApplication {
    
        public static void main(String[] args) {
    
            SpringApplication.run(JiangBoApplication.class, args);
        }
    }
    

    验证

    访问 http://localhost:8761/ ,能看到如下的结果,即结果正确。

    spring-cloud-payment

    附录

    pom.xml

    <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>
        <parent>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-parent</artifactId>
            <version>Edgware.SR6</version>
        </parent>
    
        <groupId>jiangbo.springcloud</groupId>
        <artifactId>07spring-cloud-payment</artifactId>
        <version>1.0.0</version>
        <packaging>jar</packaging>
    
        <properties>
            <java.version>1.7</java.version>
        </properties>
    
        <dependencies>
    
            <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-jdbc</artifactId>
            </dependency>
    
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <scope>runtime</scope>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <scope>provided</scope>
            </dependency>
    
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>
    
  • 相关阅读:
    Vue.Js(html5) + Java实现文件分片上传
    进程、线程基础知识全家桶,30 张图一套带走
    20 张图揭开「内存管理」的迷雾,瞬间豁然开朗
    面试官:换人!他连 TCP 这几个参数都不懂
    TCP 半连接队列和全连接队列满了会发生什么?又该如何应对?
    实战!我用 Wireshark 让你“看得见“ TCP
    IP 基础知识全家桶,45 张图一套带走
    写了Bug,误执行 rm -fr /*,我删删删删库了,要跑路吗?
    你还在为 TCP 重传、滑动窗口、流量控制、拥塞控制发愁吗?看完图解就不愁了
    硬不硬你说了算!35 张图解被问千百遍的 TCP 三次握手和四次挥手面试题
  • 原文地址:https://www.cnblogs.com/jiangbo44/p/12728869.html
Copyright © 2020-2023  润新知