当前使用版本(必填,否则不予处理)
3.5.3.2
该问题是如何引起的?(确定最新版也有问题再提!!!)
在quartz定时任务中,以sysJob的方式执行定时任务,查询是没有问题的,但是,不能更新
重现步骤(如果有就写完整)
/**
* 定时任务立即执行一次
*/
@PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')")
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
@PutMapping("/run")
@ApiOperation(value = "定时任务立即执行一次")
public AjaxResult run(@RequestBody SysJob job) throws SchedulerException {
boolean result = jobService.run(job);
return result ? success() : error("任务不存在或已过期!");
}
@Autowired
private TransferTaskService taskService;
public void outTask() {
LambdaQueryWrapper<TransferTask> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TransferTask::getTaskStatus, "0").eq(TransferTask::getTaskType, BusinessConstants.OUT_REN)
.eq(TransferTask::getStatus, "0")
.eq(TransferTask::getDelFlag, "0");
List<TransferTask> taskList = taskService.getTaskList(queryWrapper);
for (TransferTask task : taskList) {
long minutesDifference = calculateMinutesDifference(new Date(), task.getCreateTime());
if (minutesDifference >= 30) {
log.info("任务编号为{}的任务正在被删除", task.getTaskCode());
task.setDelFlag("2");
taskService.update(queryWrapper, task);
taskService.updateById(task);
log.info("任务号为{}解锁暂存位", task.getTaskCode());
lockInterval(task.getTemporaryNumber().longValue(), task.getBlankFlag(), BusinessConstants.OUT_REN);
log.info("任务号为{}解锁对应库位", task.getTaskCode());
unlockLocation(task);
log.info("任务号为{}回退虚拟库存",task.getTaskCode());
if (StringUtils.isNotEmpty(task.getOrderCode())) {
rollBackInventory(task);
}
}
}
}
List
报错信息
java.lang.reflect.InvocationTargetException: null at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.md.quartz.util.JobInvokeUtil.invokeMethod(JobInvokeUtil.java:53) at com.md.quartz.util.JobInvokeUtil.invokeMethod(JobInvokeUtil.java:31) at com.md.quartz.util.QuartzDisallowConcurrentExecution.doExecute(QuartzDisallowConcurrentExecution.java:16) at com.md.quartz.util.AbstractQuartzJob.execute(AbstractQuartzJob.java:40) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: Error updating database. Cause: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. The error may exist in com/md/task/mapper/TransTaskMapper.java (best guess) The error may involve com.md.task.mapper.TransTaskMapper.update The error occurred while executing an update Cause: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441) at com.sun.proxy.$Proxy121.update(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:288) at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:64) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) at com.sun.proxy.$Proxy140.update(Unknown Source) at com.md.task.service.impl.TransferTaskServiceImpl.update(TransferTaskServiceImpl.java:89) at com.md.task.RemoveOutTask.outTask(RemoveOutTask.java:43) ... 10 common frames omitted Caused by: org.apache.ibatis.exceptions.PersistenceException: Error updating database. Cause: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. The error may exist in com/md/task/mapper/TransTaskMapper.java (best guess) The error may involve com.md.task.mapper.TransTaskMapper.update The error occurred while executing an update Cause: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:196) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) ... 18 common frames omitted
Comment From: miemieYaho
你是不是用了自动填充然后还从线程里取值了?
Comment From: cannot-find-object
没有从线程里取值,使用mybatis在xml文件写sql是可以正常更新的,但是用mp的querywrapper的方式不行
Comment From: miemieYaho
那无法复现,你来个复现demo吧,git形式的
Comment From: cannot-find-object
@Component public class MpMetaObjectHandler implements MetaObjectHandler {
@Autowired
private HttpServletRequest request;
@Value("${token.header}")
private String header;
private String getUserName() {
String token = request.getHeader(header);
String username;
if (ObjectUtils.isNotEmpty(token)) {
username = SecurityUtils.getUsername();
} else {
username = Constants.UNKNOWN;
}
return username;
}
@Override
public void insertFill(MetaObject metaObject) {
this.setFieldValByName("createBy", getUserName(), metaObject);
this.setFieldValByName("createTime", DateUtils.getNowDate(), metaObject);
this.setFieldValByName("delFlag", "0", metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
this.setFieldValByName("updateBy", getUserName(), metaObject);
this.setFieldValByName("updateTime", DateUtils.getNowDate(), metaObject);
}
} 我确定是因为这个导致的,注释这个配置后,就没有问题了
Comment From: miemieYaho
那不就是了嘛,你定时任务哪来的request给你取值