NutzCN Logo
问答 安装照NutzBook教程添加任务类无法执行下去
发布于 6天前 作者 lishengsong 50 次浏览 复制 上一个帖子 下一个帖子
标签:

安照NutzBook教程添加任务类,一直是以下提示

 @Inject
    protected Dao dao;

    public void execute(JobExecutionContext context) throws JobExecutionException {
        log.debug("clean Non-Active User , start");
        Date deadtime = new Date(System.currentTimeMillis() - 60*1000L); // 一天, 测试的时候可以改成1小时之类的
        Cnd cnd = Cnd.where("userId", ">", 3).and("createTime", "<", deadtime).and(Cnd.exps("emailChecked", "=", false).or("email", "IS", null));
        int deleted = dao.clear(UserProfile.class, cnd);
        log.debugf("delete %d UserProfile", deleted);

        Sql sql = Sqls.create("delete from $user_table where id > 10 and not exists (select 1 from $user_profile_table where $user_table.id = uid ) and ct < @deadtime");
        sql.vars().set("user_table", dao.getEntity(User.class).getTableName());
        sql.vars().set("user_profile_table", dao.getEntity(UserProfile.class).getTableName());
        sql.params().set("deadtime", deadtime);
        dao.execute(sql);
        log.debugf("delete %d User", sql.getUpdateCount());

        log.debug("clean Non-Active User , Done");
    }
[DEBUG] 16:18:00.007 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:163) - Found IocObject(cleanNonActiveUserJob) in AnnotationIocLoader(packages=[com.gree])
[DEBUG] 16:18:00.007 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:215) - 	 >> Make...'cleanNonActiveUserJob'<class com.gree.quartz.job.CleanNonActiveUserJob>
[DEBUG] 16:18:00.007 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) - Save object 'cleanNonActiveUserJob' to [app] 
[DEBUG] 16:18:00.008 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) - Load class com.gree.quartz.job.CleanNonActiveUserJob without AOP
[DEBUG] 16:18:00.013 com.gree.quartz.job.CleanNonActiveUserJob.execute(CleanNonActiveUserJob.java:33) - clean Non-Active User , start
[DEBUG] 16:19:00.001 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:157) - Get 'cleanNonActiveUserJob'<class com.gree.quartz.job.CleanNonActiveUserJob>
[DEBUG] 16:19:00.003 com.gree.quartz.job.CleanNonActiveUserJob.execute(CleanNonActiveUserJob.java:33) - clean Non-Active User , start
[DEBUG] 16:20:00.001 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:157) - Get 'cleanNonActiveUserJob'<class com.gree.quartz.job.CleanNonActiveUserJob>
[DEBUG] 16:20:00.002 com.gree.quartz.job.CleanNonActiveUserJob.execute(CleanNonActiveUserJob.java:33) - clean Non-Active User , start
8 回复

连不上数据库吧

import org.nutz.mvc.annotation.*;

/**
* @Author :Web寻梦狮(lishengsong)
* @Date Created in 下午1:43 2017/12/24
* @Description: 主入口模块
*/

import org.nutz.mvc.ioc.provider.ComboIocProvider;
@ChainBy(args="mvc/mvc-chain.js")
@Fail("jsp:jsp.500")
@Localization(value="language/", defaultLocalizationKey="zh-CN")
@IocBy(type=ComboIocProvider.class, args={"*js", "ioc/", "*anno",
"com.gree", //搜索该包下的IocBean
"*tx", // 事务拦截 aop
"*async", // 异步执行aop
"*quartz"}) // 即添加了 org.nutz.integration.quartz.QuartzIocLoader 这个预定义的集成配置
@Modules(scanPackage = true) ////1.r.58开始默认就是true
@SetupBy(value = MainSetup.class)
public class MainModule {
}
已经连上了,可以进行增删查改

那就只能debug了

@Inject
protected Dao dao;

debug:dao = null

debug出现dao为null
@IocBean
public class CleanNonActiveUserJob implements Job {
    private static final Log log = Logs.get();
    @Inject
    protected Dao dao;

    public void execute(JobExecutionContext context) throws JobExecutionException {
        log.debug("clean Non-Active User , start");
        Date deadtime = new Date(System.currentTimeMillis() - 60*1000L); // 一天, 测试的时候可以改成1小时之类的
        Cnd cnd = Cnd.where("userId", ">", 3).and("createTime", "<", deadtime).and(Cnd.exps("emailChecked", "=", false).or("email", "IS", null));
        int deleted = dao.clear(UserProfile.class, cnd);
        log.debugf("delete %d UserProfile", deleted);

        Sql sql = Sqls.create("delete from $user_table where id > 10 and not exists (select 1 from $user_profile_table where $user_table.id = uid ) and ct < @deadtime");
        sql.vars().set("user_table", dao.getEntity(User.class).getTableName());
        sql.vars().set("user_profile_table", dao.getEntity(UserProfile.class).getTableName());
        sql.params().set("deadtime", deadtime);
        dao.execute(sql);
        log.debugf("delete %d User", sql.getUpdateCount());
        log.debug("clean Non-Active User , Done");
    }
}

quartz.properties没配job Factory?

import com.google.inject.Inject;
我用idea的自动导包功能导错了难怪
改成:import org.nutz.ioc.loader.annotation.Inject;

原来如此

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