zoukankan      html  css  js  c++  java
  • 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>
    

    第一个节点

    server:
      port: 4410
    
    spring:
      application:
        name: order
      
      datasource:
        url: jdbc:mysql://localhost/spring_cloud_order?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: 4411
    
    spring:
      application:
        name: order
      
      datasource:
        url: jdbc:mysql://localhost/spring_cloud_order?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: 4412
    
    spring:
      application:
        name: order
      
      datasource:
        url: jdbc:mysql://localhost/spring_cloud_order?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-order01

    附录

    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>04spring-cloud-order</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>
    
  • 相关阅读:
    有关程序开发中有关验证中常用的正则表达式汇总
    python学习---logging模块
    有关递归函数,返回值的学习
    设计模式之建造者模式、模版方法
    XXL-JOB使用命令行的方式启动python时,日志过多导致阻塞的解决方式
    Spring Boot后端与Angular前端进行timestamp的交互
    设计模式之代理模式
    设计模式之工厂模式
    设计模式之单例模式
    设计模式之反射机制
  • 原文地址:https://www.cnblogs.com/jiangbo44/p/12700063.html
Copyright © 2011-2022 走看看