spring cloud踩坑集锦

1.启动spring cloud,创建完成后页面出现报错

FreeMarker template error (DEBUG mode; use RETHROW in production!): The following has evaluated to null or missing: ==> replica.key [in template "eureka/navbar.ftl" at line 68, column 62] --的错误,如图所示

springcloud报错
spring cloud报错详情

检查配置发现application.properties有错误,修改方法见下图

修改完成,重新启动,问题解决!

2 启动spring cloud的消费者程序 出现Connect Timeout Exception on Url - http://localhost:8888.

项目中全局没有配置8888端口,怎么会出现8888呢,原因是pom文件中配置了

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

 

 

删掉重新启动,问题解决!

3 消费者使用服务名找不到服务提供者,报 java.net.UnknownHostException

解决方法,将RestTemplate放到application中声明,在controller类中注入RestTemplate实例,代码如下所示

Application

@SpringBootApplication
@EnableDiscoveryClient
public class ConsumerApplication {
    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }
    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
        }
}

 

Controller

@RestController
public class ConsumerController {
    @Autowired
    private RestTemplate restTemplate;
    @RequestMapping(value = "/router",method = RequestMethod.GET)
    public String router(){
        String result = restTemplate.getForObject("http://hahaha/test/test", String.class);
        return result;
    }
}

 

4 spring boot 访问/health报404

解决方式:

将/health 改为/actuator/health访问

 

5 zull和应用sessionId不一致的问题

解决方式:添加 sensitive-headers: "*"

zuul:
  host:
    maxTotalConnections: 100000  #每个服务的http客户端连接池最大连接,默认是200.适用于ApacheHttpClient,如果是okhttp无效。
    maxPerRouteConnections: 10000 #每个route可用的最大连接数,默认值是20。适用于ApacheHttpClient,如果是okhttp无效。
  semaphore:
    maxSemaphores: 10000 #最大的并发请求。是一个绝对值,无时间窗口,相当于亚毫秒级的。当请求达到或超过该设置值后,其其余就会被拒绝。默认值是100
  sensitive-headers: "*"

 

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值