Spring监听器IntrospectorCleanupListener

标签 spring listener

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/

相关文章:

java - Spring ClientInterceptor 在响应中显示空的 SOAP header

java - Spring Data Elasticsearch 找不到 geo_point 字段

java - 尽管类别正确,为什么会出现此错误?

Java 监听器继承

Java:通知提供者的实现与 hashCode 驱动的 Map

java - 帮助在 JComboBox 中的 ItemChange 时自动更改值

java - Hibernate 级联一对多无法正确连接子级和父级

java - 使用 spring 模板的 pom.xml 中的 Maven 错误

非 GUI 应用程序中的 javax.swing.event.EventListenerList

java - WindowListener 未按预期工作