Skip to content

Infer "shutdown()" as destroy method for convenient EHCache setup using @Bean [SPR-9713] #14347

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 Aug 22, 2012 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Aug 22, 2012

Peter Ledbrook opened SPR-9713 and commented

The most convenient way to set up the Ehcache provider is via the EhCacheManagerFactoryBean class. But factory beans aren't recommended for Java configuration style, so it would be good to have an alternative, such as a builder, that works well with @Bean.


Affects: 3.1.1

Issue Links:

Referenced from: commits 4c823a3

1 votes, 3 watchers

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Aug 22, 2012

Chris Beams commented

Thanks, Peter.

One question here will be how to handle destruction, i.e. calling CacheManager's #shutdown method. Option one is to return a proxy from the builder that implements DisposableBean and have #destroy invoke #shutdown. Option two is to add public no-arg methods named #shutdown to the list of recognized methods for Spring's "destroy method inference" (#13393). This list is currently limited to public no-arg methods named "close".

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I'm reducing this issue to the destroy method inference that Chris suggested, i.e. detecting "shutdown()" as a destroy method by default so that an @Bean method may simply build and return an EHCache CacheManager instance, with no further consideration necessary for destruction purposes.

EHCache itself comes with quite nice programmatic setup options, calling CacheManager.create(...) or new CacheManager(...), potentially with a Configuration argument that comes from the EHCache ConfigurationFactory. I'd like to avoid inventing our own setup API when it's really EHCache that should be evolving its configuration API and isn't too bad at it already.

And well, our EhCacheManagerFactoryBean is a rather convoluted chain of if checks that conditionally calls CacheManager.create(...) or new CacheManager(...) - it does exactly what an @Bean method should do itself. The only added value was automatic destruction which we're dealing with now.

Juergen

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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants