zoukankan      html  css  js  c++  java
  • Spring Cloud EurekaService 服务部署服务注册与发现(一)

    开发环境使用IDEA

    新建Eureka Server,新建maven项目,配置pom.xml

     <properties>
            <java.version>1.8</java.version>
            <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            </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-starter-tomcat</artifactId>
                <scope>provided</scope>
            </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>
    

      启动类修改

    @EnableEurekaServer
    @SpringBootApplication
    public class EurekaserviceApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(EurekaserviceApplication.class, args);
        }
    
    }
    

      添加配置文件

    server.port=8761
    eureka.instance.hostname=0.0.0.0
    spring.application.name = eureka_server
    eureka.client.registerWithEureka=false
    eureka.client.fetchRegistry=false
    eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:8761/eureka/
    

      启动

    打jar包,放到服务器上执行   后台挂起服务

    nohup java -jar eurekaservice-0.0.1-SNAPSHOT.jar &

    eureka客户端注册服务

    新建一个项目,修改配置

    server.port =1001
    spring.application.name=service-hi
    
    #注册eureka服务
    eureka.client.serviceUrl.defaultZone=http://地址/eureka/

    启动类中添加

    @EnableEurekaClient
    @EnableEurekaClient
    @SpringBootApplication
    public class EurekaclientApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(EurekaclientApplication.class, args);
        }
    
    }
    

      访问eureka服务可以看到service-hi 已经注册

    学习资料:https://github.com/forezp/SpringCloudLearning

  • 相关阅读:
    HTTP协议
    JavaScript学习(一)
    Cookie&Session
    注解初学
    反射初学
    XML
    Web概念
    Response对象
    Servlet
    LeetCode Notes_#617 Merge Two Binary Trees
  • 原文地址:https://www.cnblogs.com/li-lun/p/11452719.html
Copyright © 2011-2022 走看看