微服务架构
程序员文章站
2024-03-20 22:23:52
...
user-server示例
1.导入依赖
<!--客户端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
2.主配置类注解开启@EnableEurekaClient
可以不加注解–默认开启
@SpringBootApplication
@EnableEurekaClient
public class UserApplicationConfig {
public static void main(String[] args) {
SpringApplication.run(UserApplicationConfig.class);
}
}
3.application.yml
eureka:
client:
serviceUrl:
defaultZone: http://peer1:1000/eureka/,http://peer2:1001/eureka/ #连接服务器端
instance:
instance-id: user-server:3000 #当前客户端服务的id
prefer-ip-address: true # 使用ip进行注册
server:
port: 3000 #端口号
spring:
application:
name: user-server #当前应用名称