zoukankan      html  css  js  c++  java
  • springboot笔记

    1. springboot 启动之后执行方法,需要对库操作(方法挺多)

    踩坑: 使用 CommandLineRunner 实现的时候, 打jar包的时候会测试jar包,首先会运行 实现CommandLineRunner 的方法, 当时这里面使用线程做的,导致打jar包一直出不来结果. 可以把 实现该类的方法 和 tomcat 看作一个整体

    实现 CommandLineRunner
    实现 ServletContextListener() 监听器, 监听 tomcat 开启和关闭
    public class TomcatListener implements ServletContextListener {
    
        @Override
        public void contextInitialized(ServletContextEvent sce) {
            System.out.println("服务启动");
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent sce) {
            System.out.println("服务结束");
        }
    }
    @Component
    public class Text implements CommandLineRunner {
    
        @Override
        public void run(String... args) {
               
        }
    }

     2. springboot 开启定时任务需要

    @EnableScheduling
    @SpringBootApplication
    @EnableScheduling
    @MapperScan("com.example.hostinfo.dao")
    public class HostinfoApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(HostinfoApplication.class, args);
        }
    
    }
    

      

     
  • 相关阅读:
    软件工程第一次作业
    单调队列
    八皇后问题
    蓝桥-区间K大数查询
    putchar()和getchar()使用解析
    C++中的各种进制转换函数汇总及学习
    第五次团队作业
    第二次团队作业
    确定团队开发项目
    结对编程之设计电梯控制程序
  • 原文地址:https://www.cnblogs.com/han-guang-xue/p/13749496.html
Copyright © 2011-2022 走看看