1、@Configuration 和 @ComponentScan 不应重叠(Configuration和启动类不能放在在同一个包)。
2、application.yml 缩进问题,必须保持一个Tab ,冒号后一个空格再加参数。
3、配置中心刷新配置文件时注意 management.security.enabled=false 最好使用 configserver 刷新配置。
#忽略权限拦截(否则无法刷新) 单一节点刷新(/refresh) 全部节点刷新(/bus/refresh) 部分节点刷新(/bus/fresh?destination=customers:8088) 部分节点刷新(/bus/fresh?destination=customers:**)
4、Application 启动类必须在 java 下面再一层包 ,所有类必须在 启动类下一层
5、ribbon关键字支持负载均衡
@Autowired
private RestTemplate restTemplate;
return this.restTemplate.getForObject("http://tps-provider-user/" + id, User.class);
可以在application.yml 中加(配置负载均衡规则)
tps-provider-user: #请求负载均衡服务名称
ribbon:
NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RoundRobinRule #RandomRule(随机) #RoundRobinRule(轮询) 负载均衡规则
6、使用feign FeignClient的两个注意点(1. FeignClient 所在的接口中需要使用 RequestMapping 不能用 GetMapping 2. PathVariable 需要赋值 3 复杂对象 GET 不能传,POST可以)
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public User findById(@PathVariable("id") Long id);
7、健康检查配置文件只能放在application.yml里面