springcloud搭建eureka服务
1、创建一个springboot的pom工程作为父工程控制版本
案例创建的工程名为:springcloue_parent_02
修改pom文件
- 修改工程类型为pom
<packaging>pom</packaging>
- 导入依赖
<!--Springcloud的依赖库文件版本的锁定-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2、创建子工程搭建eureka服务
案例子工程名为:eureka
2.1、修改pom文件
- 继承父工程,eg:
<parent>
<groupId>com.yl</groupId>
<artifactId>springcloue_parent_02</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
- 导入依赖
<!--配置eureka依赖库组件-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
2.3、配置全局文件
spring:
application:
name: eureka
server:
port: 7001
#eureka的基本信息
eureka:
instance:
hostname: eureka.com
client:
service-url:
#也可以写成 http://${eureka.instance.hostname}:${server.port}/eureka/
#如果hostname不是localhost需要在windows配置ip映射
defaultZone: http://127.0.0.1:7001/eureka/
#本身就是注册中心,不需要注册
register-with-eureka: false
#本身就是注册中心,不需要获取注册信息
fetch-registry: false
2.4、启动类添加eureka服务端注解
package com.yl.eureka;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args) {
// SpringApplication.run(EurekaApplication.class, args);
SpringApplication springApplication=new SpringApplication(EurekaApplication.class);
springApplication.setBannerMode(Banner.Mode.OFF);
springApplication.run(args);
}
}
浏览器访问eureka服务:http://localhost:7001