1.创建一个maven工程作为父级
在该maven工程的pom文件中添加springcloud所有组件,必须基于springboot自动才能实现
<!--springcloud所有组件,必须基于springboot自动才能实现-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
</parent>
继续在该pom文件中添加依赖,作为父级工程定义版本
<!--不在子工程定义不同组件的版本号,统一由父工程定义版本-->
<dependencyManagement>
<!--springcloud考虑boot对应关系比较复杂-->
<!--导入springcloud版本总依赖,和当前springboot所有组件对应统一了-->
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
2.创建一个idea模块Module,作为上述父级工程的子工程
在子工程的pom文件中添加依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--eureka-server依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
在子工程中添加启动器及配置文件
启动类中注意添加2个注解
@SpringBootApplication
//开启eureka服务端注解
@EnableEurekaServer
public class StarterEurekaServer {
public static void main(String[] args) {
SpringApplication.run(StarterEurekaServer.class,args);
}
}
配置文件中 因为是作为注册中心,所以需要关闭抓取和注册(因为是作为服务端使用),指定端口
fetch-registry :抓取注册信息
register-with-eureka注册到eureka服务端
#port
server.port=8761
#注册中心组件配置属性
#客户端角色
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false
3.配置完成,启动服务,在浏览器端输入地址+端口即可访问
,因为此时,没有服务注册进来所以application处无信息