package cn.wizzer.app.task.commons.ext.quartz.job;
import cn.wizzer.app.match.modules.services.QttMatchService;
import cn.wizzer.app.sys.modules.services.SysTaskService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
/**
* Created by Wizzer.cn on 2015/6/27.
*/
@IocBean
public class TestJob implements Job {
private static final Log log = Logs.get();
@Inject
@Reference
protected SysTaskService sysTaskService;
@Inject
@Reference
protected QttMatchService matchService;
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap data = context.getJobDetail().getJobDataMap();
String taskId = context.getJobDetail().getKey().getName();
String hi = data.getString("hi");
log.info("Test Job hi::" + hi);
matchService.sync();
// sysTaskService.update(Chain.make("exeAt", (int) (System.currentTimeMillis() / 1000)).add("exeResult", "执行成功"), Cnd.where("id", "=", taskId));
}
}
问答
JOB定时任务注入,在TestJob注入一个新的service居然连sysTaskService都变成空
标签:
nutzwk
14 回复
[ERROR] 11:42:00.107 [defaultScheduler_Worker-2] org.quartz.core.JobRunShell - Job 9785b3bb01514968a32f8b5c648179f2.9785b3bb01514968a32f8b5c648179f2 threw an unhandled Exception:
java.lang.NullPointerException: null
at cn.wizzer.app.task.commons.ext.quartz.job.TestJob.execute(TestJob.java:37)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
[ERROR] 11:42:00.108 [defaultScheduler_Worker-2] org.quartz.core.ErrorLogger - Job (9785b3bb01514968a32f8b5c648179f2.9785b3bb01514968a32f8b5c648179f2 threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception.
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: java.lang.NullPointerException: null
at cn.wizzer.app.task.commons.ext.quartz.job.TestJob.execute(TestJob.java:37)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
... 1 common frames omitted
[WARN ] 11:42:00.108 [defaultScheduler_Worker-2] org.quartz.plugins.history.LoggingJobHistoryPlugin - Job 9785b3bb01514968a32f8b5c648179f2.9785b3bb01514968a32f8b5c648179f2 execution failed at 11:42:00 11/28/2019 and reports: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException]
org.quartz.JobExecutionException: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException]
at org.quartz.core.JobRunShell.run(JobRunShell.java:218)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: org.quartz.SchedulerException: Job threw an unhandled exception.
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
... 1 common frames omitted
Caused by: java.lang.NullPointerException: null
at cn.wizzer.app.task.commons.ext.quartz.job.TestJob.execute(TestJob.java:37)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
... 1 common frames omitted
[DEBUG] 11:42:00.108 [defaultScheduler_Worker-2] org.quartz.impl.jdbcjobstore.StdRowLockSemaphore - Lock 'TRIGGER_ACCESS' is desired by: defaultScheduler_Worker-2
[DEBUG] 11:42:00.108 [defaultScheduler_Worker-2] org.quartz.impl.jdbcjobstore.StdRowLockSemaphore - Lock 'TRIGGER_ACCESS' is being obtained: defaultScheduler_Worker-2
[DEBUG] 11:42:00.108 [defaultScheduler_Worker-2] org.quartz.impl.jdbcjobstore.StdRowLockSemaphore - Lock 'TRIGGER_ACCESS' given to: defaultScheduler_Worker-2
[DEBUG] 11:42:00.112 [defaultScheduler_Worker-2] org.quartz.impl.jdbcjobstore.StdRowLockSemaphore - Lock 'TRIGGER_ACCESS' returned by: defaultScheduler_Worker-2
[DEBUG] 11:42:00.113 [defaultScheduler_QuartzSchedulerThread] org.quartz.core.QuartzSchedulerThread - batch acquisition of 1 triggers
@wendal 嗯,是正常的,只是我加了个自己的service进去,测试类都不正常掉,我到底做了什么呢
@wendal 这个就是debug了吧
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(hikariDataSource) in AnnotationIocLoader(packages=[org.nutz.boot.starter])
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(druidDataSource) in AnnotationIocLoader(packages=[org.nutz.boot.starter])
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(r8aogkeei8gvur2e9u1k4tk3ja) in DubboConfigIocLoader@1454026445
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(052mhnkp98gajquii199pcrqtf) in DubboConfigIocLoader@1454026445
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(dubboRegistryConfig) in DubboConfigIocLoader@1454026445
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(0slv36saa2g5cpumd9fjedbre6) in DubboConfigIocLoader@1454026445
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(dubboAnnotationBean) in DubboConfigIocLoader@1454026445
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(43p8dr4g50jq4p6er0okqsdfkn) in DubboConfigIocLoader@1454026445
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(7ggjjtt0qijfrrhotjgitnn2nj) in DubboConfigIocLoader@1454026445
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.impl.NutIoc - Get '7ggjjtt0qijfrrhotjgitnn2nj'<interface cn.wizzer.app.match.modules.services.QttMatchService>
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.impl.NutIoc - >> Load definition name=7ggjjtt0qijfrrhotjgitnn2nj
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(7ggjjtt0qijfrrhotjgitnn2nj) in DubboConfigIocLoader@1454026445
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.impl.NutIoc - >> Make...'7ggjjtt0qijfrrhotjgitnn2nj'<interface cn.wizzer.app.match.modules.services.QttMatchService>
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.impl.ScopeContext - Save object '7ggjjtt0qijfrrhotjgitnn2nj' to [app]
[DEBUG] 12:28:05.017 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.impl.NutIoc - Get '43p8dr4g50jq4p6er0okqsdfkn'<>
[DEBUG] 12:28:05.025 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.impl.ScopeContext - Remove object '7ggjjtt0qijfrrhotjgitnn2nj' from [app]
[DEBUG] 12:28:05.025 [defaultScheduler_QuartzSchedulerThread] org.nutz.ioc.impl.ScopeContext - Remove object 'testJob' from [app]
[WARN ] 12:28:05.026 [defaultScheduler_QuartzSchedulerThread] org.nutz.integration.quartz.NutQuartzJobFactory - Not ioc bean? fallback to SimpleJobFactory
org.nutz.ioc.IocException: IocBean[testJob] throw Exception when creating
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:153)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:161)
at org.nutz.integration.quartz.NutQuartzJobFactory.newJob(NutQuartzJobFactory.java:27)
at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:392)
Caused by: java.lang.RuntimeException: IocBean[testJob] fail at field=[matchService]
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
... 6 common frames omitted
Caused by: org.nutz.ioc.IocException: IocBean[7ggjjtt0qijfrrhotjgitnn2nj] throw Exception when creating
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:153)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
at org.nutz.ioc.impl.NutIoc.getByType(NutIoc.java:457)
at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:66)
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
... 8 common frames omitted
Caused by: org.nutz.lang.InvokingException: Fail to invoke [org.nutz.integration.dubbo.ReferenceBean].get() by args:
For the reason: [source error] no such class: cn.wizzer.app.match.modules.services.QttMatchService
at org.nutz.lang.Invoking.invoke(Invoking.java:195)
at org.nutz.lang.Mirror.invoke(Mirror.java:1135)
at org.nutz.ioc.impl.ObjectMakerImpl$1.born(ObjectMakerImpl.java:80)
at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:78)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:117)
... 12 common frames omitted
Caused by: javassist.CannotCompileException: [source error] no such class: cn.wizzer.app.match.modules.services.QttMatchService
at javassist.CtNewMethod.make(CtNewMethod.java:84)
at javassist.CtNewMethod.make(CtNewMethod.java:50)
at com.alibaba.dubbo.common.bytecode.ClassGenerator.toClass(ClassGenerator.java:280)
at com.alibaba.dubbo.common.bytecode.ClassGenerator.toClass(ClassGenerator.java:255)
at com.alibaba.dubbo.common.bytecode.Wrapper.makeWrapper(Wrapper.java:245)
at com.alibaba.dubbo.common.bytecode.Wrapper.getWrapper(Wrapper.java:107)
at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:296)
at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:164)
at org.nutz.integration.dubbo.ReferenceBean.get(ReferenceBean.java:152)
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.nutz.lang.Invoking$NullArgInvoker.invoke(Invoking.java:77)
at org.nutz.lang.Invoking.invoke(Invoking.java:192)
... 16 common frames omitted
Caused by: javassist.compiler.CompileError: no such class: cn.wizzer.app.match.modules.services.QttMatchService
at javassist.compiler.MemberResolver.lookupClass(MemberResolver.java:410)
at javassist.compiler.MemberResolver.lookupClassByJvmName(MemberResolver.java:329)
at javassist.compiler.MemberResolver.resolveJvmClassName(MemberResolver.java:519)
at javassist.compiler.MemberCodeGen.resolveClassName(MemberCodeGen.java:1190)
at javassist.compiler.CodeGen.atDeclarator(CodeGen.java:757)
at javassist.compiler.ast.Declarator.accept(Declarator.java:103)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:381)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:53)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:381)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:53)
at javassist.compiler.CodeGen.atMethodBody(CodeGen.java:321)
at javassist.compiler.CodeGen.atMethodDecl(CodeGen.java:303)
at javassist.compiler.ast.MethodDecl.accept(MethodDecl.java:47)
at javassist.compiler.Javac.compileMethod(Javac.java:175)
at javassist.compiler.Javac.compile(Javac.java:102)
at javassist.CtNewMethod.make(CtNewMethod.java:79)
... 30 common frames omitted
[DEBUG] 12:28:05.027 [defaultScheduler_QuartzSchedulerThread] org.quartz.simpl.SimpleJobFactory - Producing instance of Job '9785b3bb01514968a32f8b5c648179f2.9785b3bb01514968a32f8b5c648179f2', class=cn.wizzer.app.task.commons.ext.quartz.job.TestJob
Caused by: javassist.compiler.CompileError: no such class: cn.wizzer.app.match.modules.services.QttMatchService
对的呀,我就在看我的matchservice还要配置什么
package cn.wizzer.app.match.modules.services;
import cn.wizzer.app.match.modules.models.QttMatch;
import cn.wizzer.framework.base.service.BaseService;
import java.util.List;
public interface QttMatchService extends BaseService<QttMatch> {
void sync();
List<QttMatch> list3days();
}
ServiceImpl
package cn.wizzer.app.match.modules.services.impl;
import cn.wizzer.app.match.modules.models.QttMatch;
import cn.wizzer.app.match.modules.models.vo.QttRootBean;
import cn.wizzer.app.match.modules.services.QttMatchService;
import cn.wizzer.framework.base.service.BaseServiceImpl;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.http.Http;
import org.nutz.http.Response;
import org.nutz.integration.jedis.RedisService;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
@IocBean(args = {"refer:dao"})
@Service(interfaceClass = QttMatchService.class)
public class QttMatchServiceImpl extends BaseServiceImpl<QttMatch> implements QttMatchService {
public QttMatchServiceImpl(Dao dao) {
super(dao);
}
@Inject
private RedisService redisService;
@Override
public void sync() {
@wendal 果然是,需要install
添加回复
请先登陆