spring boot问题记录

一、静态文件配置

spring boot 2.3.5.RELEASE

1、默认情况下,静态文件映射模板为:/**,映射路径为:"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/",见 WebMvcProperties、ResourceProperties

2、默认配置可通过配置文件覆盖

spring.mvc.static-path-pattern=/abc/**
spring.resources.static-locations=classpath:/static/

3、当使用@EnableWebMvc定义web配置时,默认配置或配置文件覆盖的配置失效,即使类无方法,此时须使用代码指定,

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer  {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
    }
}

4、在指定映射路径时,须以‘/’结尾,如"classpath:/static/",而非"classpath:/static",否则会失效

 

二、OpenFeign超时配置

spring cloud 2020.0.3  代码见https://github.com/matt-jcheng/spring-learning

1、OpenFeign超时配置如下

feign.client.config.default.logger-level = full
feign.client.config.default.connect-timeout=5000
feign.client.config.default.read-timeout=10000
feign.client.config.StoreClient.read-timeout=10000

2、如引入断路器,还需配置断路器超时

feign.circuitbreaker.enabled=true
resilience4j.timelimiter.configs.default.timeout-duration = 10000

ps:hytrix已停止更新,spring cloud对断路器进行抽象,支持多种实现,如spring-cloud-starter-circuitbreaker-resilience4j

 

posted @ 2021-06-08 18:21  Matt_Cheng  阅读(130)  评论(0编辑  收藏  举报