Spring框架中关于IntrospectorCleanupListener
的文档提到,这个监听器应该注册为web.xml中的第一个监听器。
... *
This listener should be registered as the first one in {@code web.xml}, * before any application listeners such as Spring's ContextLoaderListener. * This allows the listener to take full effect at the right time of the lifecycle. * * @author Juergen Hoeller * @since 1.1 * @see java.beans.Introspector#flushCaches() * @see org.springframework.beans.CachedIntrospectionResults#acceptClassLoader * @see org.springframework.beans.CachedIntrospectionResults#clearClassLoader */
为什么要把它放在第一个?如果不这样做会发生什么?
最佳答案
监听器按照它们被发现的顺序执行。因此第一个在启动时首先执行,在关闭时最后执行。请参阅ServletContextListener execution order了解更多相关信息。
如果这个特定的 ServletContextListener
不是第一个,它将无法刷新所有缓存的结果,因为它会错过已经加载的结果,或者会将所有结果刷新到早期这可能会导致其他类出现问题。
关于Spring监听器IntrospectorCleanupListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22525271/