java - How to use DispatcherListener in Struts 2 -


there interface dispatcherlistener in struts2. docs says

"a interface tag want execute code on init , destroy of dispatcher."

but how use interface. if create class implements interface, how should configure struts2?

when dispatcher instantiated, send listener notification when it's initialized or destroyed. reference , code samples here.

the simple usage instantiate bean container via bean tag , add in init method , remove when destroyed did classpathconfigurationprovider.

the code raw show idea

struts.xml:

<bean type="com.opensymphony.xwork2.config.packageprovider" name="mybean" class="jspbean.struts.mybean" /> 

mybean.java:

public class mybean implements configurationprovider, dispatcherlistener {   public mybean() {     system.out.println("!!! mybean !!!");   }    @override   public void dispatcherinitialized(dispatcher du) {     system.out.println("!!! dispatcherinitialized !!!");   }    @override   public void dispatcherdestroyed(dispatcher du) {     system.out.println("!!! dispatcherdestroyed !!!");   }    @override   public void destroy() {     system.out.println("!!! destroy !!!");     dispatcher.removedispatcherlistener(this);   }    @override   public void init(configuration configuration) throws configurationexception {     system.out.println("!!! init !!!");     dispatcher.adddispatcherlistener(this);   }    @override   public boolean needsreload() {     return false;   }    @override   public void loadpackages() throws configurationexception {    }    @override   public void register(containerbuilder builder, locatableproperties props) throws configurationexception {    } } 

the output:

15:27:50  info (org.apache.struts2.spring.strutsspringobjectfactory:42) - ... initialized struts-spring integration !!! mybean !!! !!! init !!! jul 18, 2013 3:27:51 pm org.apache.catalina.startup.hostconfig deploydirectory !!! dispatcherinitialized !!! [2013-07-18 06:28:11,102] artifact jspbean:war exploded: artifact deployed info: valid shutdown command received via shutdown port. stopping server instance. info: stopping service catalina !!! dispatcherdestroyed !!! 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -