Skip to content

Allow custom CacheResolver to be configured #5201

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
snicoll opened this issue Feb 23, 2016 · 0 comments
Closed

Allow custom CacheResolver to be configured #5201

snicoll opened this issue Feb 23, 2016 · 0 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Feb 23, 2016

The current CacheAutoConfiguration has the following condition: @ConditionalOnMissingBean({ CacheManager.class, CacheResolver.class }). If you want to configure your own custom CacheResolver, something along the lines of

@Bean
@Lazy
public CacheResolver fooBarCacheResolver(CacheManager cacheManager) {
    return new AbstractCacheResolver(cacheManager) { ... }
}

Then it blows up because the CacheManager is no longer configured. And it isn't because we've defined a CacheResolver.

But we haven't configured the CacheResolver: we just have configured a CacheResolver that can be used in a dedicated service.

Maybe we should use a bean name rather than a type.

The exception is also misleading:

java.lang.IllegalStateException: No CacheResolver specified, and no bean of type CacheManager found. Register a CacheManager bean or remove the @EnableCaching annotation from your configuration.

@snicoll snicoll added type: bug A general bug for: team-attention An issue we'd like other members of the team to review labels Feb 23, 2016
@snicoll snicoll self-assigned this Feb 23, 2016
@snicoll snicoll removed the for: team-attention An issue we'd like other members of the team to review label Feb 24, 2016
@snicoll snicoll modified the milestones: 1.4.0.M1, 1.4.0.M2 Feb 24, 2016
@snicoll snicoll changed the title Cache auto-configuration triggers early init and prevents the use of custom CacheResolver Allow custom CacheResolver to be configured Feb 29, 2016
@snicoll snicoll added type: enhancement A general enhancement and removed type: bug A general bug labels Feb 29, 2016
henrikerola pushed a commit to henrikerola/spring-boot that referenced this issue Mar 3, 2016
Previously, if a bean of type `CacheResolver` was present in the context
the whole cache auto-configuration would back off. If said
`CacheResolver` hasn't been defined via the `CachingConfigurer`
infrastructure, the application context would fail with a rather
unpleasant error message.

It can be quite common to define custom `CacheResolver` beans as the cache
annotations allow to defines custom cache resolvers per operation. This
commit makes sure that the cache auto-configuration will back-off only if
the `CacheResolver` is named `cacheResolver`.

Closes spring-projectsgh-5201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant