• 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>
    
  • 相关阅读:
    机器学习框架之sklearn简介
    ubuntu 16.04下使用 python pip的安装问题。
    ubuntu 16.04 搭建git小型服务器
    使用config 来管理ssh的会话
    【linux】su、sudo、sudo su、sudo -i的用法和区别
    【python】确保文件写入结束
    【python】描述符descriptor
    【python】类(资料+疑惑)
    【pymongo】mongodb cursor id not valid error
    【python】继承关系和isinstance
  • 原文地址:https://www.cnblogs.com/jiangbo44/p/12728869.html
Copyright © 2020-2023  润新知