springboot 详解 (六)servlet & scheduled & listener

  1. 云栖社区>
  2. 博客>
  3. 正文

springboot 详解 (六)servlet & scheduled & listener

curiousby 2016-11-17 17:17:00 浏览324 评论0

摘要:    ---------------------------------------------------------------------------------------------------------------- springboot 详解 (一) hellowo...

 

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

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捐助),没钱捧个人场,谢谢各位。



 
 
 谢谢您的赞助,我会做的更好!

 

 

 

 

【云栖快讯】阿里巴巴小程序繁星计划,20亿补贴第一弹云应用免费申请,限量从速!  详情请点击

网友评论