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 »

12月 132019
 

问题与原因

启动spring boot程序时,报异常,导致程序启动失败,遇到形如下面的错误:

A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/Integration]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
……

然而,这个只是结果,实际上并不能定位问题,笔者继续找异常,看到类似下面的错误: Continue reading »

11月 242019
 

现象

spring boot 启动时,连接mysql 8数据库报错errorCode 0, state 08001

原因

1. spring boot项目中,pom文件中配置的mysql驱动版本与mysql数据库版本不一致

此时修改pom文件中的版本即可,可以使用下面的配置:

……
<groupId>mysql
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
……

同时,yml文件中的mysql驱动类文件最好修改成

……
driver-class-name: com.mysql.cj.jdbc.Driver
……

Continue reading »

11月 242019
 

问题

导入excel文件时,偶发bug:

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [C:\Users\AppData\Local\Temp\tomcat.4266029690466887869.8037\work\Tomcat\localhost\ROOT] is not valid
	at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:112)
	at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:86)
	at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:79)
	at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1104)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:936)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)

原因

Spring boot项目在导入文件时,没有找到指定文件夹。
子所以是偶发的问题,是因为spring boot项目本身在启动后会自动在Temp文件夹中创建若干临时文件夹,而操作系统可能会定期删除这些临时文件夹。linux也有类似操作系统自动清空临时文件夹的操作,参见这篇文章CentOS7的/tmp目录自动清理规则

 
Continue reading »

9月 052019
 

问题

spring boot + spring cloud,上传附件时遇到如下错误:

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (11963927) exceeds the configured maximum (10485760)

错误信息表示上传附件报超出自带tomacat限制大小(默认1M)
Continue reading »