zoukankan      html  css  js  c++  java
  • springboot、监听器

    1.启动类上添加注解

     @ServletComponentScan  
    @SpringBootApplication()
    @ComponentScan(basePackages={"com"})
    @ServletComponentScan  //scans from the package of the annotated class (@WebServlet, @WebFilter, and @WebListener) 
    public class DemoApplication {
    
        public static void main(String[] args) {
            
            //此设置一定要在SpringApplication.run(DemoApplication.class, args); 前面进行设置
            //System.setProperty("spring.devtools.restart.enabled","false");
            SpringApplication.run(DemoApplication.class, args);
        }
    
    }

    2.监听类

    @WebListener
    public class MyHttpSessionListener implements HttpSessionListener{
    
        public static int online = 0;
        
        @Override
        public void sessionCreated(HttpSessionEvent arg0) {
            // TODO Auto-generated method stub
              System.out.println("创建session");
              online ++;
              System.out.println("当前在线人数:"+online);
            
        }
    
        @Override
        public void sessionDestroyed(HttpSessionEvent arg0) {
            // TODO Auto-generated method stub
             System.out.println("销毁session");
             online --;
            
        }
    
    }
  • 相关阅读:
    chartjs 初步
    QT “error: error writing to -: Invalid argument”
    OTL mySQL
    qtcteater pro 文件配置
    Python os.readlink() 方法
    Python os.read() 方法
    Python os.popen() 方法
    Python os.pipe() 方法
    Python os.pathconf() 方法
    ThinkPHP框架前后台的分页调用
  • 原文地址:https://www.cnblogs.com/dztHome/p/10339272.html
Copyright © 2011-2022 走看看