Since Spring Framework 4.2, DefaultContextCache supported an LRU (least recently used) eviction policy via a custom LruCache which extended LinkedHashMap. The LruCache reacted to LinkedHashMap's removeEldestEntry() callback to remove the LRU context if the maxSize of the cache was exceeded. Due to the nature of the implementation in LinkedHashMap, the removeEldestEntry() callback is invoked after a new entry has been stored to the map. Consequently, a Spring ApplicationContext (C1) was evicted from the cache after a new context (C2) was loaded and added to the cache, leading to failure scenarios such as the following. - C1 and C2 share an external resource -- for example, a database. - C2 initializes the external resource with test data when C2 is loaded. - C1 cleans up the external resource when C1 is closed. - C1 is loaded and added to the cache. - C2 is loaded and added to the cache before C1 is evicted. - C1 is evicted and closed. - C2 tests fail, because C1 removed test data required for C2. To address such scenarios, this commit replaces the custom LruCache with custom LRU eviction logic in DefaultContextCache and revises the put(MergedContextConfiguration, ApplicationContext) method to delegate to a new evictLruContextIfNecessary() method. This commit also introduces a new put(MergedContextConfiguration, LoadFunction) method in the ContextCache API which is overridden by DefaultContextCache to ensure that an evicted context is removed and closed before a new context is loaded to take its place in the cache. In addition, DefaultCacheAwareContextLoaderDelegate has been revised to make use of the new put(MergedContextConfiguration, LoadFunction) API. Closes gh-21007
Spring Framework

This is the home of the Spring Framework: the foundation for all Spring projects. Collectively the Spring Framework and the family of Spring projects are often referred to simply as "Spring".
Spring provides everything required beyond the Java programming language for creating enterprise applications for a wide range of scenarios and architectures. Please read the Overview section of the reference documentation for a more complete introduction.
Code of Conduct
This project is governed by the Spring Code of Conduct. By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior to spring-code-of-conduct@spring.io.
Access to Binaries
For access to artifacts or a distribution zip, see the Spring Framework Artifacts wiki page.
Documentation
The Spring Framework maintains reference documentation (published and source), GitHub wiki pages, and an API reference. There are also guides and tutorials across Spring projects.
Micro-Benchmarks
See the Micro-Benchmarks wiki page.
Build from Source
See the Build from Source wiki page and the CONTRIBUTING.md file.
Continuous Integration Builds
Information regarding CI builds can be found in the Spring Framework Concourse pipeline documentation.
Stay in Touch
Follow @SpringCentral, @SpringFramework, and its team members on 𝕏. In-depth articles can be found at The Spring Blog, and releases are announced via our releases feed.
License
The Spring Framework is released under version 2.0 of the Apache License.