Description
Expected Behavior
Not sure this is a bug, but I have not been able to explain it. Mainly, I'm hoping for an explanation that I can use to correct the issue.
In my library project I have a single service:
@Singleton @Requires(property = "gts.oci.enabled", value = "true", defaultValue = "true") public class OciAccessClientMicronaut {
an annotation that adds the service into consuming application contexts:
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Import(classes = {OciAccessClientMicronaut.class, OciAuthPropertiesMicronaut.class, OciObjectStoragePropertiesMicronaut.class, OciStreamingPropertiesMicronaut.class}) public @interface EnableOciAccessClientMicronaut { }
and two test cases that inject it for use:
`
@MicronautTest(environments = {"svcon"},
rebuildContext = true)
@EnableOciAccessClientMicronaut
@testinstance(TestInstance.Lifecycle.PER_CLASS)
public class OciAccessClientMicronautComponentTest {
@Inject
//@Any
private OciAccessClientMicronaut undertest;
`
`
@MicronautTest(environments = {"svcoff"},
rebuildContext = true)
//@EnableOciAccessClientMicronaut - works at compile time, so we only want one in suite
@testinstance(TestInstance.Lifecycle.PER_CLASS)
public class OciAccessClientMicronautServicesOffComponentTest {
@Inject
//@Any
private OciAccessClientMicronaut undertest = null;
`
Expected Behavior:
As there is only the one registration of the service in the project source, I expect there to be just one bean registration for the class. So, the two test cases should successfully execute without any qualifier applied at the injection site.
Actual Behaviour
Instead, with no qualifier at the injections site in the test cases, I get:
Caused by: io.micronaut.context.exceptions.NonUniqueBeanException: Multiple possible bean candidates found: [com.oracle.gbu.gaes.oci.OciAccessClientMicronaut, com.oracle.gbu.gaes.oci.OciAccessClientMicronaut]
After doing some debugging, I figured out that applying the @Any annotation works around the problem, but I feel like I need to know why it's necessary.
One thing I noticed is that there bean reference classes are generated:
target/classes/com/oracle/gbu/gaes/oci:
$OciAccessClientMicronaut$Definition$Reference.class
$OciAccessClientMicronaut$Definition.class
target/test-classes/com/oracle/gbu/gaes/oci:
$OciAccessClientMicronautComponentTest$OciAccessClientMicronaut0$Definition$Reference.class
$OciAccessClientMicronautComponentTest$OciAccessClientMicronaut0$Definition.class
and these are the source of the twin bean definitions. I understand the one in "main", but why is the one in "test" being generated? As a test, I deleted the classes in "test" and the @Any annotation was no longer necessary.
Steps To Reproduce
No response
Environment Information
OS: Lunux
JDK: 11
Example Application
No response
Version
3.2.0