欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

springboot 详解 (六)servlet & scheduled & listener

程序员文章站 2022-04-22 08:32:30
...

 

 ----------------------------------------------------------------------------------------------------------------

springboot 详解 (一) helloworld                                    下载demo          

springboot 详解 (二) crud                                             下载demo     

springboot 详解 (三) 多数据源                                        下载demo      

springboot 详解 (四)redis & filter                                    下载demo    

springboot 详解 (五)interceptor                                       下载demo     

springboot 详解 (六)servlet & scheduled & listener         下载demo     

springboot 详解(七) dubbox & zookeeper   下载(productor) 下载(constumser)

springboot 同步解耦 异步化 下载demo

springboot jenkins docker 部署 

springboot 详解(八) springboot & springcloud 

----------------------------------------------------------------------------------------------------------------

 

 

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

 
@WebServlet(urlPatterns="/webservlet/weixin", description="Servlet的说明") 
public class WeixinServlet extends HttpServlet{

    private static final long serialVersionUID = -8685285401859800066L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.sendRedirect("/SpringBootWebDemo/web/static/forward"); 
    }

}

 

 

 @ServletComponentScan // servlet 自动扫描 

@EnableTransactionManagement  //事务自动扫描
@SpringBootApplication 
@ServletComponentScan  // servlet 自动扫描 
public class SpringBootSampleApplication {

    
     
    
    public static void main(String[] args) {
        SpringApplication.run(SpringBootSampleApplication.class, args);
    }


}

 

 

 

 

@Configuration
@EnableScheduling 
public class SchedulerTask {
    
    private final Logger logger = LoggerFactory.getLogger(SchedulerTask.class);

    @Scheduled(cron = "0/2 * * * * ?")  
    public void scheduler() {
        logger.info("===================== scheduled ====================");
    }


}

 

 

 

@WebListener
public class ServerHttpSessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        System.out.println("Session 被创建");

        
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        System.out.println("Session 被销毁"); 
        
    }

    
}

 

 

@WebListener
public class ServerServletContextListener implements ServletContextListener{

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("ServletContex初始化");

        
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("ServletContex销毁");

        
    }

  
}

 

 

 

 

 

 

 

 

 

 

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。


springboot 详解 (六)servlet  & scheduled & listener
            
    
    博客分类: springboot springboot详解servletscheduledlistener springboot 详解 (六)servlet  & scheduled & listener
            
    
    博客分类: springboot springboot详解servletscheduledlistener springboot 详解 (六)servlet  & scheduled & listener
            
    
    博客分类: springboot springboot详解servletscheduledlistener 
 
 
 谢谢您的赞助,我会做的更好!