Skip to content

EhCacheCacheManager does not close underlying CacheManager [SPR-11680] #16303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Apr 9, 2014 · 5 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 9, 2014

Michael Russo opened SPR-11680 and commented

EhCacheCacheManager should implement and register a destroy method that calls cacheManager.shutdown(), which should be called when EhCacheCacheManager bean is destroyed by Spring container.

When using XML config, the common practice is to use the EhCacheManagerFactoryBean, which happens to implement DisposableBean and calls cacheManager.shutdown() as expected.


Affects: 4.0.3

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Michael Russo commented

I'm intending to configure a Spring MVC Web project to use Ehcache via java config. I found one suggestion for doing this via stackoverflow: http://stackoverflow.com/questions/21944202/using-ehcache-in-spring-4-without-xml

The answer shows the creation of a org.springframework.cache.CacheManager spring bean by using the org.springframework.cache.ehcache.EhCacheCacheManager. The problem with this answer is that the EhCacheCacheManager doesn't seem to support closing the underlying EhCache CacheManager by calling its shutdown() method.

When using XML config, the common practice is to use the EhCacheManagerFactoryBean, which happens to implement DisposableBean and calls cacheManager.shutdown() as expected.

This looks like a bug to me. I believe the EhCacheCacheManager should also register a destroy method that calls cacheManager.shutdown().

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Since EhCacheCacheManager is set up with an externally specified CacheManager, it has an adapter role and isn't really meant to control the lifecycle of that external CacheManager instance.

Instead, it's advisable to define the native net.sf.ehcache.CacheManager as a dedicated bean (using XML or using an @Bean method) which makes its lifecycle managed by the container. Spring should also be able to autodetect EhCache's native "shutdown()" method in such a scenario. The EhCacheCacheManager adapter is then just a separate bean that points to the net.sf.ehcache.CacheManager bean, not affecting the latter's lifecycle.

Hope that helps,

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Michael Russo commented

That helps a lot, thanks! I verified that when registering net.sf.ehcache.CacheManager as a bean, its shutdown method is called successfully, without me even having to specify the bean's destroyMethod.

The part I still don't understand is, how is this automatic? The documentation for the @Bean annotation's destroyMethod() states:

As a convenience to the user, the container will attempt to infer a destroy method against an object returned from the @Bean method. For example, given a @Bean method returning an Apache Commons DBCP BasicDataSource, the container will notice the close() method available on that object and automatically register it as the destroyMethod. This 'destroy method inference' is currently limited to detecting only public, no-arg methods named 'close'.

Either way, consider this issue resolved. Thanks for your help!

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Apr 10, 2014

Juergen Hoeller commented

The automatic detection of "shutdown()" is a rather recent effect: see #14347. Seems we have to mention this in the @Bean javadoc... I'll sort this out.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Marking this as "Won't Fix" from the EhCacheCacheManager perspective.

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants