1.用eclipse 创建maven Project 项目如下图所示:
点击下一步:
点击finish
打开 pom.xml 文件,如下图所示:
2. 添加需要得pom 文件
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
3. 在resources 文件下面添加配置文件
文件结构如下图
application.propertis 文件内容如下:
spring.application.name=eureka-server-wyz1
server.port=1002
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
3.添加启动文件Application.java 具体内容如下图:
package com.wyz.springCloud;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class Application {
public static void main(String[] args){
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
}
4. 通过如下方式:启动程序,具体操作如图所示:
点击运行后
出现如上图时候,说明成功。
在浏览器输入:http://localhost:1002/ 如下图所示: