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

Micronaut Primary bean not recognised as Primary in Grails 4 #11367

Closed
4 tasks done
erichelgeson opened this issue Jul 15, 2019 · 4 comments
Closed
4 tasks done

Micronaut Primary bean not recognised as Primary in Grails 4 #11367

erichelgeson opened this issue Jul 15, 2019 · 4 comments

Comments

@erichelgeson
Copy link
Contributor

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Use a mn bean in a grails service that has 2 qualifying beans (in this case lettuce)

Expected Behaviour

The bean marked as Primary should be used.

Actual Behaviour

***************************
APPLICATION FAILED TO START
***************************

Description:

Field statefulRedisConnection in grails.ExampleService required a single bean, but 2 were found:
	- io.lettuce.core.api.StatefulRedisConnection(Primary): defined in null
	- io.lettuce.core.pubsub.StatefulRedisPubSubConnection($DefaultRedisClientFactory$RedisPubSubConnectionDefinition): defined in null

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

Work around

Add qualifier

@Qualifier("io.lettuce.core.api.StatefulRedisConnection(Primary)")

Environment Information

  • Operating System: macOs 10.14.5
  • Grails Version: 4.0.0
  • JDK Version: 11.0.2
  • Container Version (If Applicable): n/a

Example Application

@erichelgeson erichelgeson changed the title Micronaut Primary bean not recogzised as Primary in Grails 4 Micronaut Primary bean not recognised as Primary in Grails 4 Jul 15, 2019
@graemerocher graemerocher added this to the grails-4.0.1 milestone Jul 16, 2019
@jameskleeh jameskleeh self-assigned this Oct 9, 2019
@andersaaberg
Copy link
Contributor

@jameskleeh : I upgraded the example project (erichelgeson/mnbeansPrimary@0a35af5) to Grails 4.0.1 (andersaaberg/mnbeansPrimary@3396fa6), but it still fails on startup with the error:
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'io.lettuce.core.api.StatefulRedisConnection<?, ?>' available: expected single matching bean but found 2: io.lettuce.core.pubsub.StatefulRedisPubSubConnection($DefaultRedisClientFactory$RedisPubSubConnectionDefinition),io.lettuce.core.api.StatefulRedisConnection(Primary)

@jameskleeh
Copy link
Contributor

@andersaaberg I have added tests for this in grails3-functional-tests. Ensure you have micronaut-spring:1.0.2 on your classpath

andersaaberg pushed a commit to andersaaberg/grails3-functional-tests that referenced this issue Oct 18, 2019
Expanded integrationtest to demonstrate that it is not possible to inject StatefulRedisConnection without @qualifier("io.lettuce.core.api.StatefulRedisConnection(Primary)")
@andersaaberg
Copy link
Contributor

andersaaberg commented Oct 18, 2019

@jameskleeh I have extended your test with injection of an actual StatefulRedisConnection bean: https://github.com/grails/grails3-functional-tests/pull/22

The test only passes when using the qualifier as workaround: @Qualifier("io.lettuce.core.api.StatefulRedisConnection(Primary)")

Am I doing something wrong?

@jameskleeh
Copy link
Contributor

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

No branches or pull requests

5 participants