Skip to content

Latest commit

 

History

History
51 lines (37 loc) · 1.81 KB

14-WebContextBean.md

File metadata and controls

51 lines (37 loc) · 1.81 KB

⌂ Catalog
⇦ Previous section 13 - Template       ⇨ Next section 15 - Formula

14 - Web Context bean

Introduction

server web context start or shutdown will run java class bean.
WebSystemCtxBeanSupportListener will auto create bean( ContextInitializedAndDestroyedBean ) and call execute(ServletContextEvent event) method for INITIALIZE or DESTROY.

You must first understand the following framework

  1. ServletContextListener https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/ServletContextListener.html

Create a event bean

The class need extends ContextInitializedAndDestroyedBean
Example:

public class CleanTempUploadForContextInitAndDestroy extends ContextInitializedAndDestroyedBean {
	private static final long serialVersionUID = 5017459384696932226L;

	@Override
	public void execute(ServletContextEvent event) throws Exception {
	  
	  // do something ...
	  
	}
	
}

Create config

Add config item. Image of WEB-CTX-BEAN-mgr1

Image of WEB-CTX-BEAN-mgr2

And need restart tomcat server to effective

ContextInitializedAndDestroyedBean

Name return description
execute(ServletContextEvent event) void do event function, WebSystemCtxBeanSupportListener will call it