Skip to content

LoadingCache on top of Repository forms bean dependency cycle #14782

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
pmihalcin opened this issue Oct 11, 2018 · 2 comments
Closed

LoadingCache on top of Repository forms bean dependency cycle #14782

pmihalcin opened this issue Oct 11, 2018 · 2 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@pmihalcin
Copy link

pmihalcin commented Oct 11, 2018

When I add LoadingCache on top of Spring Data Repository, so that it can load entities when needed, the application fails to start because beans in application context form a cycle.

I created minimalistic sample: https://github.com/pmihalcin/spring-data-repository-cache for you to easily see the problem.

This issue occurs using Boot 2.0.5.RELEASE, but it doesn't occur with Boot 1.5.10.RELEASE

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 11, 2018
@philwebb
Copy link
Member

Issue #4158 (commit 8e0a94f) makes adds an explicit dependsOn from the entityManager to the cacheManager.

@snicoll
Copy link
Member

snicoll commented Oct 13, 2018

This was refined more recently in #14181.

Our contract is that the cache infrastructure is fully initialized by the time Hibernate starts so that it can be used for second level caching. Your sample requires hibernate to be fully loaded before the cache gets a chance to construct itself.

I supposed the sample is a simplistic view of what you're actually doing (as adding @Cacheable on the finder would do what all that code does). But there's not much else we should do here I am afraid. If you want to pursue using loading cache then you could consider injecting an ObjectProvider rather than requiring the full resolution of the repository on startup. Alternatively, your setup is super simple and you could create the CacheManager yourself so that things happen in the order that you want.

@snicoll snicoll closed this as completed Oct 13, 2018
@snicoll snicoll added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants