Java: Writing your own listener

Sometimes it is necessary to write your own Java listener, what is quite simple.

Include the necessary library in the pom.xml

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
</dependency>

Create the listener

package me.kamwo.example.util;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ConfigurationListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent event) {
        // Do your stuff
        System.setProperty("org.apache.el.parser.COERCE_TO_ZERO", "false");
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
    }

}

Add the listener to the web.xml

<listener>
	<display-name>Configuration Listener</display-name>
	<listener-class>me.kamwo.example.util.ConfigurationListener</listener-class>
</listener>