首页>代码>如何优雅的关闭Spring容器并销毁Bean实例>/register-shutdown-hook-invoking-destroy-methods-shutdown/src/main/java/com/memorynotfound/spring/core/lifecycle/Run.java
package com.memorynotfound.spring.core.lifecycle;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Run {

    public static void main(String... args) throws InterruptedException {
        ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("app-config.xml");
        Logger logger = context.getBean(Logger.class);
        System.out.println(logger);
        logger = context.getBean(Logger.class);
        System.out.println(logger);
//        logger.destroy();
        context.registerShutdownHook();
    }
}
最近下载更多
zxk329  LV1 2021年2月23日
最近浏览更多
全栈小白  LV34 2023年1月8日
981352576  LV4 2022年5月10日
devin2019 2022年3月30日
暂无贡献等级
最代码-宋家辉  LV61 2021年11月1日
xiao菜  LV2 2021年6月2日
幸运疯子  LV13 2021年5月16日
liyunbo 2021年5月8日
暂无贡献等级
wangchen0112 2021年5月6日
暂无贡献等级
hwpok9  LV5 2021年4月27日
dafeiyu  LV10 2021年4月6日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友