NutzCN Logo
问答 nutzboot depose 没有执行 为什么呢
发布于 1152天前 作者 Hamming 1689 次浏览 复制 上一个帖子 下一个帖子
标签:

nutzboot depose 没有执行 为什么呢

package io.nutz.nutzsite;

import com.alibaba.fastjson.JSON;
import io.nutz.nutzsite.common.base.Globals;
import io.nutz.nutzsite.common.config.GenConfig;
import io.nutz.nutzsite.common.manager.AsyncManager;
import io.nutz.nutzsite.common.mvc.MyActionChainMaker;
import io.nutz.nutzsite.common.utils.ShiroUtils;
import io.nutz.nutzsite.common.utils.TreeUtils;
import io.nutz.nutzsite.module.data.services.AsinService;
import io.nutz.nutzsite.module.sys.models.*;
import io.nutz.nutzsite.module.sys.services.*;
import org.nutz.boot.NbApp;
import org.nutz.conf.NutConf;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.util.Daos;
import org.nutz.el.opt.RunMethod;
import org.nutz.el.opt.custom.CustomMake;
import org.nutz.integration.quartz.QuartzJob;
import org.nutz.integration.quartz.QuartzManager;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.*;
import org.nutz.lang.Encoding;
import org.nutz.lang.Mirror;
import org.nutz.lang.random.R;
import org.nutz.lang.util.NutMap;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.*;
import org.quartz.Scheduler;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.servlet.http.HttpServletRequest;
import java.lang.management.ManagementFactory;
import java.nio.charset.Charset;
import java.sql.Driver;
import java.sql.DriverManager;
import java.util.Enumeration;
import java.util.List;

/**
 * @author haiming
 */
@IocBean(create = "init", depose = "depose")
@IocBy(args={"*slog","*tx"})
@Localization(value = "locales/", defaultLocalizationKey = "zh-CN")
@ChainBy(type= MyActionChainMaker.class, args={})
public class MainLauncher {
    private static final Log log = Logs.get();

    @Inject("refer:$ioc")
    private Ioc ioc;
    @Inject
    protected Dao dao;
    @Inject
    protected PropertiesProxy conf;

    @Inject
    private UserService userService;
    @Inject
    private MenuService menuService;
    @Inject
    private TaskService taskService;
    @Inject
    private AsinService asinService;

    /**
     * 启动方法
     * @param args
     */
    public static void main(String[] args) {
        new NbApp().setArgs(args).setPrintProcDoc(true).run();
        NutConf.USE_FASTCLASS = true;
    }


    @At({"/", "/index"})
    @Ok("re")
    public String index(HttpServletRequest req) {
        User user = ShiroUtils.getSysUser();
        if (!ShiroUtils.isAuthenticated()) {
            return "th:/login.html";
        }
        user =userService.fetchLinks(user,"dept|image");
        req.setAttribute("user", user);
        List<Menu> menuList = menuService.getMenuList(user.getId());
        req.setAttribute("menus", TreeUtils.getChildPerms(menuList, "0"));
        return "th:/index.html";
    }

    /**
     * 系统介绍
     *
     * @return
     */
    @At({"/sys/main"})
//    @Ok("th:/main_v1.html")
    @Ok("th:/main.html")
    public NutMap main() {
        return NutMap.NEW().setv("version", Globals.getConfig("version"));
    }

    /**
     * NB自身初始化完成后会调用这个方法
     */
    public void init() {
        // 环境检查oogle
        if (!Charset.defaultCharset().name().equalsIgnoreCase(Encoding.UTF8)) {
            log.warn("This project must run in UTF-8, pls add -Dfile.encoding=UTF-8 to JAVA_OPTS");
        }
        // 初始化系统变量
        Globals.getInstance();
        initSysData();
        initSysTask();
        /**
         * 自定义EL表达式
         * 文档
         * http://nutzam.com/core/el/overview.html
         */
        CustomMake.me().register("array2str", new RunMethod(){
            @Override
            public Object run(List<Object> fetchParam) {
                String tmp = JSON.toJSONString(fetchParam);
                return tmp;
            }
            @Override
            public String fetchSelf() {
                return "array2str";
            }
        });

    }

    /**
     * 清空定时任务 否则会存在僵尸java进程
     */
    public void depose() {
        log.info("depose asin scan state");
        asinService.restoreScanState();

        log.info("depose AsyncManager Task");
        AsyncManager.me().shutdown();

        log.info("depose Sys Task");
        QuartzManager quartzManager = ioc.get(QuartzManager.class);
        quartzManager.clear();
        // 解决quartz有时候无法停止的问题
        try {
            ioc.get(Scheduler.class).shutdown(true);
        } catch (Exception e) {

        }
        // 非mysql数据库,或多webapp共享mysql驱动的话,以下语句删掉
        try {
            Mirror.me(Class.forName("com.mysql.jdbc.AbandonedConnectionCleanupThread")).invoke(null, "shutdown");
        } catch (Throwable e) {

        }
        // 解决com.alibaba.druid.proxy.DruidDriver和com.mysql.jdbc.Driver在reload时报warning的问题
        // 多webapp共享mysql驱动的话,以下语句删掉
        Enumeration<Driver> en = DriverManager.getDrivers();
        while (en.hasMoreElements()) {
            try {
                Driver driver = en.nextElement();
                String className = driver.getClass().getName();
                log.debug("deregisterDriver: " + className);
                DriverManager.deregisterDriver(driver);
            }
            catch (Exception e) {
            }
        }
        try {
            MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
            ObjectName objectName = new ObjectName("com.alibaba.druid:type=MockDriver");
            if (mbeanServer.isRegistered(objectName)) {
                mbeanServer.unregisterMBean(objectName);
            }
            objectName = new ObjectName("com.alibaba.druid:type=DruidDriver");
            if (mbeanServer.isRegistered(objectName)) {
                mbeanServer.unregisterMBean(objectName);
            }
        } catch (Exception ex) {

        }
    }

    /**
     * 初始化数据库
     */
    private void initSysData() {
        // 创建数据库
        Daos.createTablesInPackage(dao, "io.nutz.nutzsite", false);
        Daos.createTablesInPackage(dao, "org.nutz.plugins.slog.bean", false);
        // 若必要的数据不存在,则初始化数据库
        if (0 == dao.count(User.class)) {
            String data = GenConfig.getFileData("data/menu.json");
            List<Menu> menuList = JSON.parseArray(data,Menu.class);
            menuList = Menu.getMenuList(menuList,"0");
            for(Menu menu:menuList){
                dao.fastInsert(menu);
            }
            String roleJson = GenConfig.getFileData("data/role.json");
            List<Role> roleList = JSON.parseArray(roleJson,Role.class);
            for(Role role:roleList){
                role.setId(R.UU32().toLowerCase());
                dao.fastInsert(role);
                if("admin".equals(role.getRoleKey())){
                    role.setMenus(menuList);
                    dao.insertRelation(role, "menus");
                }
            }
            String userJson = GenConfig.getFileData("data/user.json");
            List<User> userList = JSON.parseArray(userJson,User.class);
            for(User user:userList){
                user.setId(R.UU32().toLowerCase());
                dao.fastInsert(user);
                if("admin".equals(user.getLoginName())){
                    user.setPassword("123456");
                    userService.resetUserPwd(user);
                    user.setRoles(roleList);
                    dao.insertRelation(user, "roles");
                }
            }

            String deptJson = GenConfig.getFileData("data/dept.json");
            List<Dept> deptList = JSON.parseArray(deptJson,Dept.class);
            for(Dept d:deptList){
                dao.fastInsert(d);
            }
            String taskJson = GenConfig.getFileData("data/task.json");
            List<Task> taskList = JSON.parseArray(taskJson,Task.class);
            for(Task t:taskList){
                dao.fastInsert(t);
            }
        }
        //其他表懒得写了 有需要 自行添加
    }

    /**
     * 初始化 定时任务
     */
    private void initSysTask() {
        QuartzManager quartzManager = ioc.get(QuartzManager.class);
        quartzManager.clear();
        List<Task> taskList = taskService.query( Cnd.where("status", "=", true));
        for (Task sysTask : taskList) {
            try {
                QuartzJob qj = new QuartzJob();
                qj.setJobName(sysTask.getId());
                qj.setJobGroup(sysTask.getId());
                qj.setClassName(sysTask.getJobClass());
                qj.setCron(sysTask.getCron());
                qj.setComment(sysTask.getNote());
                qj.setDataMap(sysTask.getData());
                quartzManager.add(qj);
            } catch (Exception e) {
                log.error(e.getMessage());
            }
        }
    }
}

5 回复

打包成wa还是独立运行?

停止的日志

Disconnected from the target VM, address: '127.0.0.1:50696', transport: 'socket'
[INFO ] 10:49:32.249 org.eclipse.jetty.server.AbstractConnector.doStop(AbstractConnector.java:381) - Stopped ServerConnector@153f66e7{HTTP/1.1, (http/1.1)}{0.0.0.0:8099}
[INFO ] 10:49:32.251 org.eclipse.jetty.server.session.HouseKeeper.stopScavenging(HouseKeeper.java:149) - node0 Stopped scavenging
[INFO ] 10:49:32.253 org.nutz.boot.starter.nutz.mvc.NbMvcLoading.depose(NbMvcLoading.java:54) - Nutz.Mvc[nutz] is deposing ...
[INFO ] 10:49:32.253 org.nutz.boot.starter.nutz.mvc.NbMvcLoading.depose(NbMvcLoading.java:70) - Nutz.Mvc[nutz] is down in 0ms
[INFO ] 10:49:32.256 org.eclipse.jetty.server.handler.ContextHandler$Context.log(ContextHandler.java:2362) - Cleaning up Shiro Environment
[INFO ] 10:49:32.258 org.eclipse.jetty.server.handler.ContextHandler.doStop(ContextHandler.java:1154) - Stopped o.e.j.w.WebAppContext@6818fd48{/,[file:///D:/IdeaProjects/jptopkeywords/target/classes/static/, jar:file:/C:/Users/Kricss/.m2/repository/org/nutz/nutzboot-starter-swagger/2.4.2.v20201205/nutzboot-starter-swagger-2.4.2.v20201205.jar!/static/],STOPPED}

Process finished with exit code 130

是因为自定义动作链吗
@ChainBy(type= MyActionChainMaker.class, args={})

【阿里云】双11爆款优惠特价服务器
1核2G1M 180元/3年
2核2G5M 58元/1年
2核4G5M 600元/3年
4核8G5M 1500/3年
活动地址:
https://www.aliyun.com/minisite/goods?taskPkg=1111ydsrwb&pkgSid=5985&userCode=wbqjs7bw

【腾讯云】双11爆款优惠特价服务器
1核2G5M 50G云盘,50元/1年
2核4G8M 80G云盘,74元/1年
2核4G3M 50G云盘,968元/3年(16:00开抢)
4核8G5M 50G云盘,818元/1年(19:00开抢)
活动地址:
https://curl.qcloud.com/mMBBtBDp

没大佬解答一下吗

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