Aop工具注入调用

求助,使用quartz做调度器时出问题,找不出原因了

quartz执行类

image.png


image.png

[ERROR]-[Thread: quartzScheduler_QuartzSchedulerThread]-[org.quartz.core.ErrorLogger.schedulerError()]: An error occured instantiating job to be executed. job= 'pro.12'

org.quartz.SchedulerException: Problem instantiating class 'com.test.config.quartz.job.ProJob' [See nested exception: java.lang.IllegalArgumentException: Can not set com.test.business.service.ProductService field com.test.business.service.BillService.productService to com.test.business.service.BillService$$EnhancerByJFinal]

at org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:58)

at org.quartz.simpl.PropertySettingJobFactory.newJob(PropertySettingJobFactory.java:69)

at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127)

at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:392)

Caused by: java.lang.IllegalArgumentException: Can not set com.test.business.service.ProductService field com.test.business.service.BillService.productService to com.test.business.service.BillService$$EnhancerByJFinal

at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)

at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)

at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)

at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:75)

at java.lang.reflect.Field.set(Field.java:764)

at com.jfinal.aop.AopFactory.doInject(AopFactory.java:167)

at com.jfinal.aop.AopFactory.doGetSingleton(AopFactory.java:93)

at com.jfinal.aop.AopFactory.doGet(AopFactory.java:65)

at com.jfinal.aop.AopFactory.get(AopFactory.java:48)

at com.jfinal.aop.Aop.get(Aop.java:101)

at com.test.config.quartz.job.ProJob.<init>(ProJob.java:12)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

at java.lang.Class.newInstance(Class.java:442)

at org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:56)

... 3 more


评论区

JFinal

2020-08-19 13:47

关键异常信息:
Can not set com.test.business.service.ProductService field com.test.business.service.BillService.productService to com.test.business.service.BillService$$EnhancerByJFinal]

变量类型不对,可能是你映射有问题,估计是你添加了:
AopManager.me().addMapping(...)

造成类型问题,检查一下

lzw0128

2020-08-19 14:01

@JFinal 没有添加。是只要被调用的方法里有@Inject就报错,不太了解这里面原理

JFinal

2020-08-19 15:04

@lzw0128 这就很奇怪了,都用一下 Aop.get 试试

lzw0128

2020-08-19 15:28

@JFinal 可以执行到方法,但是方法内随便调用new Test().findById(id)这种都会报空指针

JFinal

2020-08-19 19:54

@lzw0128 应该是 Test 没有添加映射

lzw0128

2020-08-20 10:53

@JFinal Undertow加上addHotSwapClassPrefix("org.quartz.")就可以了

JFinal

2020-08-20 12:49

@lzw0128 jfinal undertow 项目已添加该内置配置:
https://gitee.com/jfinal/jfinal-undertow/commit/1a106bd687b4edb5f571dad946576eedefe5d30a

lzw0128

2020-08-20 15:45

@JFinal 谢谢波总

热门反馈

扫码入社