SpringCloud-2.X 学习笔记03 Eureka Consumer 搭建
程序员文章站
2022-07-13 09:31:27
...
1 搭建服务
2 添加注解
package com.xu.eureka.consumer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
public class EurekaConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaConsumerApplication.class, args);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
3 修改配置
server:
port: 8080 # 应用服务 WEB 访问端口
spring:
thymeleaf:
encoding: UTF-8 # 模板文件编码
cache: false # 是否启用缓存
prefix: classpath:/templates/ # 访问template下的html文件需要配置模板
suffix: .html # 模板文件后缀
resources:
static-locations: classpath:/static/ # spring 静态资源扫描路径
application:
name: EurekaConsumer # 应用名称
main:
allow-bean-definition-overriding: true
eureka:
client:
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/
#自定义负载均衡策略
EurekeClient:
ribbon:
#NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
4 查看结果
上一篇: 基于Docker搭建nacos集群
下一篇: 自定义相机中如何实现二维码扫描功能