NutzCN Logo
问答 使用定时任务 没有加载@Inject注入的服务
发布于 2610天前 作者 wx_dc1uhcoqb670vfspa24d 2575 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

@IocBean public class ProductOrderJob implements Job { @Inject protected Dao dao; }

启用定时任务,没有注入Dao 是不哪里需要设置一下

21 回复

日志贴一下看看

[WARN ] 2017-10-29 15:50:00,099 org.nutz.integration.quartz.NutQuartzJobFactory.newJob(NutQuartzJobFactory.java:30) - Not ioc bean? fallback to SimpleJobFactory
org.nutz.ioc.IocException: IocBean[productOrderJob] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:245)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:152)
	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:375)
Caused by: java.lang.RuntimeException: IocBean[productOrderJob] fail at field=[refundService]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:136)
	... 6 more
Caused by: org.nutz.ioc.IocException: IocBean[refundService] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 8 more
Caused by: java.lang.RuntimeException: IocBean[refundService] fail at field=[unionpayClient]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:136)
	... 11 more
Caused by: org.nutz.ioc.IocException: IocBean[class:org.firenut.pay.api.UnionpayClient] none ioc bean match class=org.firenut.pay.api.UnionpayClient
	at org.nutz.ioc.impl.NutIoc.getByType(NutIoc.java:411)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:66)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 13 more
[DEBUG] 2017-10-29 15:50:00,101 org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:51) - Producing instance of Job '575db1f4b41a4b88b50cd86b63b8eae5.575db1f4b41a4b88b50cd86b63b8eae5', class=cn.wizzer.app.web.commons.quartz.job.ProductOrderJob
[INFO ] 2017-10-29 15:50:00,101 org.quartz.plugins.history.LoggingJobHistoryPlugin.jobToBeExecuted(LoggingJobHistoryPlugin.java:469) - Job 575db1f4b41a4b88b50cd86b63b8eae5.575db1f4b41a4b88b50cd86b63b8eae5 fired (by trigger 575db1f4b41a4b88b50cd86b63b8eae5.575db1f4b41a4b88b50cd86b63b8eae5) at:  15:50:00 10/29/2017
[DEBUG] 2017-10-29 15:50:00,101 org.quartz.core.JobRunShell.run(JobRunShell.java:201) - Calling execute on job 575db1f4b41a4b88b50cd86b63b8eae5.575db1f4b41a4b88b50cd86b63b8eae5
[ERROR] 2017-10-29 15:50:00,101 org.quartz.core.JobRunShell.run(JobRunShell.java:211) - Job 575db1f4b41a4b88b50cd86b63b8eae5.575db1f4b41a4b88b50cd86b63b8eae5 threw an unhandled Exception: 

UnionpayClient没加@IocBean?

var ioc = {
    unionpayClient : {
        type : "org.firenut.pay.api.UnionpayClient",
        args : []
    }
};

嗯嗯 我配一个ioc就好啦 谢谢啦

public class UnionpayClient {
    private WxpayClient wxpayClient;
    private AlipayClient alipayClient;

    public UnionpayClient() {
    }

    public void initOkHttpClient(OkHttpClient client) {
        OkWebUtils.initHttpClient(client);
    }

    public WxpayClient getWxpayClient() {
        return this.wxpayClient;
    }

    public void setWxpayClient(WxpayClient wxpayClient) {
        this.wxpayClient = wxpayClient;
    }

    public AlipayClient getAlipayClient() {
        return this.alipayClient;
    }

    public void setAlipayClient(AlipayClient alipayClient) {
        this.alipayClient = alipayClient;
    }
}

这是注入的服务
private WxpayClient wxpayClient;
private AlipayClient alipayClient;
在引用的时候为null
@Inject
private UnionpayClient unionpayClient;

你在js里配了这个bean,那么注解就无效了

何不全部走注解呢,除了dao的那几个bean

[WARN ] 2017-11-06 15:40:41,175 org.nutz.integration.quartz.NutQuartzJobFactory.newJob(NutQuartzJobFactory.java:30) - Not ioc bean? fallback to SimpleJobFactory
org.nutz.ioc.IocException: IocBean[productOrderJob] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:245)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:152)
	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:375)
Caused by: java.lang.RuntimeException: IocBean[productOrderJob] fail at field=[refundService]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:136)
	... 6 more
Caused by: org.nutz.ioc.IocException: IocBean[refundService] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 8 more
Caused by: java.lang.RuntimeException: IocBean[refundService] fail at field=[unionpayClient]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:136)
	... 11 more
Caused by: org.nutz.ioc.IocException: IocBean[class:org.firenut.pay.api.UnionpayClient] none ioc bean match class=org.firenut.pay.api.UnionpayClient
	at org.nutz.ioc.impl.NutIoc.getByType(NutIoc.java:411)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:66)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 13 more

UnionpayClient 是封装的支付类

去掉js引入的IOCBean 正常的Bean装载也没能执行

UnionpayClient加@IocBean没?

@IocBean
public class RefundService {
   @Inject
    private UnionpayClient unionpayClient;

}

如果加了@IocBean,那检查@IocBy是否涵盖了它所在的package

UnionpayClient是引入的第三方jar包,所以我一开始的想法是通过js的方法导入Bean
但是bean中的字段却并没有装载

原来是第三方类

var ioc = {
    unionpayClient : {
        type : "org.firenut.pay.api.UnionpayClient",
        fields : {
            wxpayClient : {refer:"wxpayClient"},
            alipayClient :  {refer:"alipayClient"} 
        }
    }
};

那我还是得通过js导入吧?怎样才能使其字段不是null呢?

这样的配置 我试过啦,我再试试

alipayClient也得声明

public class UnionpayClient {
    private WxpayClient wxpayClient;

    public UnionpayClient() {
    }

    public void initOkHttpClient(OkHttpClient client) {
        OkWebUtils.initHttpClient(client);
    }

    public WxpayClient getWxpayClient() {
        return this.wxpayClient;
    }

    public void setWxpayClient(WxpayClient wxpayClient) {
        this.wxpayClient = wxpayClient;
    }
}

initOkHttpClient方法怎么注入

var ioc = {
    unionpayClient : {
        type : "org.firenut.pay.api.UnionpayClient",
        fields : {
            wxpayClient : {refer:"wxpayClient"},
            alipayClient :  {refer:"alipayClient"},
            initOkHttpClient : {refer:"okHttpClientEncrypt"}
        }
    }
};

我查看了下文档 都是根据getter setter形式注入,这样的 有操作得思路吗

@IocBean
public class OkHttpClientEncrypt {
}

干脆就继承UnionpayClient 吧

WxpayClient AlipayClient 分享一下吧

添加回复
请先登陆
回到顶部