springboot 2.0.2升级到springboot 2.6.7问题记录

我用的springboot+jpa+thymeleaf

1. BaseRepositoryFactory的getTargetRepository变了

原来的

@Override 
protected Object getTargetRepository(RepositoryInformation information) { 
    return new BaseJpaRepository((Class)information.getDomainType(), em);
}

改为:

 @Override
 protected JpaRepositoryImplementation<?, ?> getTargetRepository(RepositoryInformation information,EntityManager entityManager) {
    JpaEntityInformation<?, Serializable> entityInformation = this.getEntityInformation(information.getDomainType());
    Object repository = this.getTargetRepositoryViaReflection(information, new Object[]{entityInformation, entityManager});
    Assert.isInstanceOf(BaseJpaRepository.class, repository);
    return (JpaRepositoryImplementation)repository;
}

2. 查询的排序变了

Sort sort = new Sort(Direction.ASC, "字段");

改为:

Sort sort = Sort.by(Sort.Direction.ASC, "字段");

3. thymeleaf的引用模板页不起作用了。所有页面都乱了。

引用模板的部分layout:decorator改成使用新的标签 layout:decorate 进行页面布局。

4. 由于thymeleaf升级,页面会报一个错误

Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Only variable expressions returning numbers or booleans are allowed in this context, any other datatypes are not trusted in the context of this expression, including Strings or any other object that could be rendered as a text literal. A typical case is HTML attributes for event handlers (e.g. "onload"), in which textual data from variables should better be output to "data-*" attributes and then read from the event handler. (template: "itilView/other/createFlow2" - line 913, col 168)
th:onclick="turn_other_process+${item_btn.key}"

改为

th:onclick="turn_other_process[[${item_btn.key}]]"

4. 文件上传大小设置

 @Bean  
    public MultipartConfigElement multipartConfigElement() {  
        MultipartConfigFactory factory = new MultipartConfigFactory();  
        //单个文件最大  
        factory.setMaxFileSize("10240MB"); //KB,MB  
        /// 设置总上传数据总大小  
        factory.setMaxRequestSize("102400MB");  
        return factory.createMultipartConfig();  
    } 

改为在application里面直接设置

spring.http.multipart.maxFileSize: 10240MB  
spring.http.multipart.maxRequestSize: 102400MB

5. 修改restTemplate的超时时间:

    @Autowired
    private RestTemplateBuilder builder;
 
    // 使用RestTemplateBuilder来实例化RestTemplate对象,spring默认已经注入了RestTemplateBuilder实例
    @Bean
    public RestTemplate restTemplate() {
        return builder.setConnectTimeout(2000).setReadTimeout(2000).build();
    }

改为:

    @Bean
    public RestTemplate restTemplate() {
		HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
        httpRequestFactory.setConnectionRequestTimeout(60*1000);
        httpRequestFactory.setConnectTimeout(60*1000);
        httpRequestFactory.setReadTimeout(60*1000);
        return new RestTemplate(httpRequestFactory);
    }

6. 升级后,restTemplate 的url格式要求严格了。本来项目是spring cloud的结构,多个微服务。升级后,有些地方URL存在//,就不能访问了。需要调整。

例如:

http://127.0.0.1/微服务名称/方法名

以前为了安全起见,可能存在
http://127.0.0.1/微服务名称//方法名  
的情况
微服务名称后面自带的"/"全部去掉

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值