4月 302020
 

众所知周,spring cloud 1.5版本与2.x版本差异很大,官方没有做向下兼容,导致大家对于升级spring cloud版本都非常慎重。

此处,首先推荐阅读官方给出的迁移手册 Spring Boot 2.0 Migration Guide

虽然是英文的,但建议还是好好读读。

预备知识

废话一下:
升级操作前务必要对spring, spring boot, spring cloud版本、各自关联有清晰的认识。 Continue reading »

4月 272020
 

现象

spring项目部署linux时读取字体失败导致绘图时输出乱码,比如说调用Graphics2D graphic绘图时用到字体,却输出乱码。

原因

字体文件找不到,比如说开发环境是windows,可能是使用“微软雅黑”字体,是正常的,但部署到线上(往往是linux),就会是乱码。 Continue reading »

4月 272020
 

现象

以jar包方式部署系统,想读取resource或是template下面的文件时,报 File Not Found

我遇到的情况是,整个项目达成了一个包,在开发环境(windows + idea)读取文件没问题,但在预发布环境(centos, 打成一个jar部署),则报错。
使用

jar -xvf xxx.jar

命令解压jar后,大体结构如下:

BOOT-INF
META-INF
org
...

继续往下找可以找到我想要读取的资源文件,说明打包正常,那只能说明:
以jar形式部署后,采用一般的java 读取文件的API接口,可能无法从jar包直接读取到文件。 Continue reading »

3月 182020
 

方法:
1、将大文件分成多个小文件
2、检查mysql的max_allowed_packet参数配置,命令如下:

show variables like '%max_allowed_packet%';

适当调大该参数,比如在启动mysql client端时,通过加参数的方式,在客户端调整该参数

mysql --max_allowed_packet=32M

更多修改方法参见官方文档:B.4.2.9 Packet Too Large,以及这篇 How to change max_allowed_packet size

参考资料

3月 092020
 

在spring boot的application.yml文件中配置:

# 配置sql打印日志
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

如果是application.properties,添加:

# 配置sql打印日志
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

打印结果类似这样: Continue reading »

3月 092020
 

表现

仅配置单个数据源时,mybatis plus的save/saveBatch接口调用正常
配置多个数据源、动态切换时,mybatis plus的save接口调用正常,saveBatch调用失败,报错如下

org.apache.ibatis.exceptions.PersistenceException: 
### Error flushing statements.  Cause: org.apache.ibatis.executor.BatchExecutorException: com.xxx.survey.mapper.SurveyAnswerMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: 对象名 't_survey_answer' 无效。
### Cause: org.apache.ibatis.executor.BatchExecutorException: com.xxx.survey.mapper.SurveyAnswerMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: 对象名 't_survey_answer' 无效。
 at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
 at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:255)
 at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.saveBatch(ServiceImpl.java:128)
 at com.baomidou.mybatisplus.extension.service.IService.saveBatch(IService.java:58)
 at com.baomidou.mybatisplus.extension.service.IService$$FastClassBySpringCGLIB$$f8525d18.invoke(<generated>)
 at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
 at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:736)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
 at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
 at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:671)
 at com.xxx.survey.service.impl.SurveyAnswerServiceImpl$$EnhancerBySpringCGLIB$$dbeefaf3.saveBatch(<generated>)
 at com.xxx.survey.ServiceTest.testGetAttendanceRecord(ServiceTest.java:91)
 at sun.refl

Continue reading »

3月 032020
 

本文主要关注如何使用mybatis/mybatis plus连接SQL Server数据库,因此将省略其他项目配置、代码。

框架选择

应用框架:spring boot
ORM框架:mybatis plus(对于连接数据库而言,mybatis和mybatis plus其实都一样)
数据库连接池:druid

pom依赖

此处仅给出我的配置,mybatis/druid请依据自己项目的需要进行选择。 Continue reading »