一、服务搭建
1.引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
2.添加@EnableEurekaServer注解
3.在application.yml中配置 eureka地址
server:
port: 10086
spring:
application:
name: eureka-server
eureka:
client:
service-url: #eureka的地址信息
defaultZone: http://127.0.0.1:10086/eureka
二、服务注册
1.引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
2.添加@EnableEurekaClient注解
3.在application.yml中配置 eureka地址
server:
port: 8089
spring:
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql:///cloud-user
application:
name: userService #user服务名称
mybatis-plus:
type-aliases-package: entity
mapper-locations: classpath:*/mepper/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:10086/eureka
三、服务发现