服务注册
注册服务,就是在服务上添加Eureka的客户端依赖,客户端代码会自动把服务注册到EurekaServer中。
- 在服务中添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
- 在主类中添加注解,开启Eureka客户端功能
@EnableDiscoveryClient
- 配置application.yml文件
server:
port: 9091
spring:
application: #应用名
name: user-service
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/Bike
username: root
password: admin123
mybatis:
mapper-locations: classpath:/userMapper.xml
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:10086/eureka