Description
This issue is very similar to the now fixed issue spring-projects/spring-framework#21583 .
Andy Wilkinson:
In short, the problem is that InternalResourceViewResolver calls AutowireCapableBeanFactory.initializeBean(Object existingBean, String beanName) using the complete URL as the beanName. The bean name is then used by AbstractAutoProxyCreator.wrapIfNecessary(Object, String, Object) as the key when it caches the fact that no advice applies to it. When the possible redirect URLs are unbounded this leads to an unbounded number of entries being added to the cache.
In this case is ThymeleafViewResolver
, not InternalResourceViewResolver
.
Juergen Hoeller commented
AbstractAutoProxyCreator is fundamentally right to make assumptions about the bean name: The supplied name should identify the kind of bean, not the individual instance. From that perspective, it's wrong for RedirectView to use the specified URL as bean name (as per #13413 when this was introduced); I've changed it to use the redirect prefix ("redirect:") to identify this kind of bean. Being at it, as of 5.1, we're also using the forward prefix ("forward:") for forward views (InternalResourceView) now, sending those through applyLifecycleMethods as well (even if just for the optional bean name and application context there since it may help for tracking).
Steps to reproduce:
-
Run the program (see attached)
-
Make many requests to it (e.g. with apache benchmark
ab -n 200000 -c 100 http://localhost:8080/
) -
Check that the heap memory goes up and doesn't come down after doing a manual GC
-
Or check with the debugger that the map AnnotationAwareAspectJAutoProxyCreator.advisedBeans contains thousands of entries