在B站学习的springcloud的学习记录,第二天,最难不过坚持。
配置和环境:idea2022 jdk8 mysql8.0
本文章只用于学习和分享,欢迎大家的建议,讨论和指点。
目录
创建一个eureka注册中心
继续是跟着杨哥五步走:建model 改pom 写yml 主启动 写业务
建model
添加依赖
<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">
<parent>
<artifactId>cloud2023</artifactId>
<groupId>com.liangliang</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-eureka-server7001</artifactId>
<packaging>war</packaging>
<name>cloud-eureka-server7001 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!--eureka服务器-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<finalName>cloud-eureka-server7001</finalName>
</build>
</project>
写application.yml文件
server:
port: 7001 #端口号
spring:
application:
name: eurekaservice #服务名称
eureka:
client:
service-url: #eureka的地址信息
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #eureka集群的信息
register-with-eureka: false
fetch-registry: false
写主启动类
比平时的启动类添加多一个注解
@SpringBootApplication
@EnableEurekaServer
public class EurekaMain7001 {
public static void main(String[] args) {
SpringApplication.run(EurekaMain7001.class,args);
}
}
@EnableEureaServer将该model创建成一个eureka服务注册中心
运行该程序
将服务注册到eureka中
将之前创建的两个微服务注册进eureka注册中心中。
按照步骤改pom->写yml->主启动类的步骤,将两个服务添加