Skip to content
Advertisement

How to use DispatcherListener in Struts 2

There is a interface DispatcherListener in Struts2. The docs says

“A interface to tag those that want to execute code on the init and destroy of a Dispatcher.”

But how to use this interface. If I create a class that implements this interface, how should I configure it to Struts2?

Advertisement

Answer

When a Dispatcher is instantiated, it could send to the listener notification when it’s initialized or destroyed. The reference and code samples are from here.

The simple usage is to instantiate a bean by the container via bean tag and add themselves in the init method and remove themselves when destroyed like it did by the ClasspathConfigurationProvider.

The code is raw just for to show you the idea

struts.xml:

JavaScript

MyBean.java:

JavaScript

The output:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement