Using ServletContextListener in SpringBoot

SpringBoot uses ServletContextListener to initialize API interface information. An error was generated: (below)

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

how to use? Implement the contexInitialized method in the ServletContextListener interface. In the modified method, the initialization operation when the web application is started is implemented. Here I am initializing the API interface.

@WebListener
public class StartListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent sce) {
        new APIUrl();
    }

    public void contextDestroyed(ServletContextEvent sce) {
    }
}

Solve the above error: add annotations to the Springboot startup class

@ServletComponentScan

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325548414&siteId=291194637