自己学习的时候写的一个CRUD功能
具体操作请看下面:
创建springcloud-eureka-7001 maven项目
导入maven依赖
<!--Eureka注册中心 7001-->
<artifactId>springcloud-eureka-7001</artifact
<dependencies>
<!--eureka的服务提供者包-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
<!--热部署工具-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
配置application.yml
server:
port: 7001
#Eureka配置
eureka:
instance:
hostname: localhost #Eureaka服务端的实例名称
client:
register-with-eureka: false #表示是否向Eureka注册中心注册自己
fetch-registry: false #如果fetch-registry为false,则表示自己为注册中心
service-url: #监控页面
#点进去参考源码,可看到默认的url端口配置为8761,我们设置为自己的端口。
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
配置EurekaServer_7001启动类
@SpringBootApplication
@EnableEurekaServer //表示为Eureka服务端的启动类,可以接收别人注册进来
public class EurekaServer_7001 {
public static void main(String[] args) {
SpringApplication.run(EurekaServer_7001.class,args);
}
}
此时,我们的Eureka注册中心已经搭建完毕,
总共分为4步:
- 导入依赖
- 编写配置文件
- 开启这个功能 @Enablexxx
- 配置类