Skip to content
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

[caffeine] : Multiple possible bean candidates found when using caffeine with service discovery [DiscoveryClientCacheConfiguration, DefaultCacheConfiguration] #725

Open
kirpi4ik opened this issue Feb 19, 2024 · 0 comments

Comments

@kirpi4ik
Copy link

Expected Behavior

No response

Actual Behaviour

Exception thrown during discovery client initialization

Caused by: io.micronaut.context.exceptions.NonUniqueBeanException: Multiple possible bean candidates found: [DiscoveryClientCacheConfiguration, DefaultCacheConfiguration]
	at io.micronaut.context.DefaultBeanContext.findConcreteCandidate(DefaultBeanContext.java:2428)
	at io.micronaut.context.DefaultApplicationContext.findConcreteCandidate(DefaultApplicationContext.java:606)
	at io.micronaut.context.DefaultBeanContext.lastChanceResolve(DefaultBeanContext.java:3212)
	at io.micronaut.context.DefaultBeanContext.pickOneBean(DefaultBeanContext.java:3156)
	at io.micronaut.context.DefaultBeanContext.findConcreteCandidateNoCache(DefaultBeanContext.java:3112)
	at io.micronaut.context.DefaultBeanContext.findConcreteCandidate(DefaultBeanContext.java:3095)
	at io.micronaut.context.DefaultBeanContext.findBeanDefinition(DefaultBeanContext.java:2745)
	at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2720)
	at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1729)
	at io.micronaut.context.AbstractBeanResolutionContext.getBean(AbstractBeanResolutionContext.java:89)
	at io.micronaut.context.AbstractInitializableBeanDefinition.resolveBean(AbstractInitializableBeanDefinition.java:2165)
	... 91 common frames omitted

From initial investigation
DefaultSyncCache initialization is failing due to this constructor which injects base class CacheConfiguration

    @Inject
    public DefaultSyncCache(
            CacheConfiguration cacheConfiguration,
            ApplicationContext applicationContext,
            ConversionService conversionService) {
        this.cacheConfiguration = cacheConfiguration;
        this.applicationContext = applicationContext;
        this.conversionService = conversionService;
        this.cache = buildCache(cacheConfiguration);
    }

There are two beans which extend this class, one from cache-caffeine[DefaultCacheConfiguration] and one from cashe-core[DiscoveryClientCacheConfiguration]

Steps To Reproduce

With discovery client and caffeine enabled :

implementation("io.micronaut.cache:micronaut-cache-caffeine")
implementation("io.micronaut.discovery:micronaut-discovery-client")

enable discovery cache in application.yaml

micronaut:
  caches:
    discovery-client:
      enabled: true
      maximum-size: 20
      charset: 'UTF-8'
      expire-after-access: 300s

Environment Information

JDK graalvm-jdk-21.0.2+13.1
OS: Win11x64

Example Application

No response

Version

4.2.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant