创建eureka-client模块
在上一篇中的eureka-demo父工程上创建eureka-client模块
编写pom文件
<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>com.lzh</groupId>
<artifactId>eureka-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>eureka-client</artifactId>
<packaging>jar</packaging>
<name>eureka-client</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<!-- Eureka 客户端依赖 -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
编写主启动类
@SpringBootApplication
//eureka客户端注解
@EnableDiscoveryClient
public class EurekaClientApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(EurekaClientApplication.class)
.web(WebApplicationType.SERVLET)
.run(args);
}
}
创建配置文件
spring:
application:
name: eureka-client
server:
port: 30000
eureka:
client:
service-url:
# eureka 服务端地址
defaultZone: http://localhost:20000/eureka/
instance:
instance-id: eureka-client
启动
先运行上篇我们创建的注册中心,eureka-server,运行成功后,再启动eureka-client的主启动类,启动完成后,访问eureka-server。
得到如上界面,在Instances currently registered with Eureka中有我们刚刚创建的client的注册信息,说明我们启动并注册成功。