Eureka 微服务注册中心搭建

 

 本机IP为  192.168.1.102

 

1.   新建Maven项目   eureka

 

2.   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>
    <groupId>com.java</groupId>
    <artifactId>eureka</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <name>${project.artifactId}</name>

    <!-- 配置版本常量 -->
    <properties>
        <jdk.version>1.8</jdk.version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
    </parent>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>


        <!-- 热部署 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
            <version>1.2.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

 

 

3.   application.yml

server: 
  port: 8080
 
eureka: 
  instance:
    hostname: 192.168.1.102 
  client: 
    register-with-eureka: false 
    fetch-registry: false 
    service-url: 
      defaultZone: http://192.168.1.102:8080/eureka/
      
 

 

 

 

4.   EurekaStarter.java

package com.java.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class EurekaStarter extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(EurekaStarter.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(EurekaStarter.class);
    }

}

 

 

 5. 启动测试

运行EurekaStarter.java

浏览器输入URL

http://127.0.0.1:8080/

 

 

本机IP为  192.168.1.102

也可以输入    

http://192.168.1.102:8080/

访问

 

 

 

 

 

 

.

posted @ 2018-11-08 19:35  诚信天下  阅读(906)  评论(0编辑  收藏  举报