spring boot加web监听器 ServletContextListener

首先 需要继承ServletContextListener

public class ParamInitListener implements ServletContextListener

然后在启动类上加上@ServletComponentScan注解

之前看到往上的教程都这么写,没有写注解后面如果不是同包下要加上路径,搞了好多天没搞好。。

@ServletComponentScan(value= "com.smp.listener")

这样才能扫到对应包下类,如果是多个包就和@ComponentScan一样处理加{}

猜你喜欢

转载自blog.csdn.net/a397525088/article/details/81126019