You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider caching interface-derived BeanInfo instances in CachedIntrospectionResults [SPR-16568] #21110
CachedIntrospectionResults currently caches the results for the Class passed to forClass(Class), but not for the Class passed to getBeanInfo(Class, boolean). If multiple classes passed to forClass(Class) implement the same interface, multiple BeanInfo instances will be created for that interface. For example, in a small Spring Boot sample application 27 BeanInfo instances are created for org.springframework.core.Ordered.
This doesn't appear to have too much impact in a small application, but as an application grows and there are more classes implementing the same interfaces, I wonder if caching would become increasingly beneficial?
Since Introspector.getBeanInfo is supposed to use a cache internally, it seems like a net-negative for us to call it with IGNORE_ALL_BEANINFO for interfaces since this seems to bypass the cache... We could just call the standard variant, at the expense of the introspector looking for a BeanInfo class on the classpath then but caching the outcome at least. This would avoid the need for locally caching the interface-derived BeanInfo instances ourselves.
This seems to be the case indeed, so I'll go with that solution. It doesn't hurt for the interface lookup to consider BeanInfo classes (that simply won't ever exist); we're simply trading off an extra classpath lookup once per interface over rebuilding the BeanInfo instances for every occurrence of the interface on an introspected bean class. Also, the general spring.beaninfo.ignore=true flag suppresses that extra classpath lookup for interfaces anyway.
Activity
spring-projects-issues commentedon Mar 8, 2018
Juergen Hoeller commented
Since
Introspector.getBeanInfois supposed to use a cache internally, it seems like a net-negative for us to call it withIGNORE_ALL_BEANINFOfor interfaces since this seems to bypass the cache... We could just call the standard variant, at the expense of the introspector looking for aBeanInfoclass on the classpath then but caching the outcome at least. This would avoid the need for locally caching the interface-derivedBeanInfoinstances ourselves.spring-projects-issues commentedon Mar 8, 2018
Juergen Hoeller commented
This seems to be the case indeed, so I'll go with that solution. It doesn't hurt for the interface lookup to consider
BeanInfoclasses (that simply won't ever exist); we're simply trading off an extra classpath lookup once per interface over rebuilding theBeanInfoinstances for every occurrence of the interface on an introspected bean class. Also, the generalspring.beaninfo.ignore=trueflag suppresses that extra classpath lookup for interfaces anyway.