新建Module
该Module为Maven项目,命名为microservice-eureka-server-2001
修改pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| <?xml version="1.0" encoding="UTF-8"?> <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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <packaging>war</packaging>
<parent> <groupId>org.example</groupId> <artifactId>microservice</artifactId> <version>1.0-SNAPSHOT</version> </parent>
<name>microservice-eureka-server-2001</name> <artifactId>microservice-eureka-server-2001</artifactId>
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> </dependencies>
</project>
|
application.yml配置
在resources中新建application.yml
1 2 3 4 5 6 7 8 9 10 11 12
| server: port: 2001 context-path: /
eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
|
Eureka服务启动类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| package com.ledao;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication @EnableEurekaServer public class EurekaApplication_2001 {
public static void main(String[] args) { SpringApplication.run(EurekaApplication_2001.class, args); } }
|
运行
运行Eureka服务启动类后,在浏览器地址栏输入:http://localhost:2001/