Does CDI with Spring DI annotation works when its from an external dependency?

Viewed 544

I'm writing a code that needs to be compatible with both Quarkus and Spring DI. I am using both DI and Spring Boot Properties extensions, the Spring Boot Extension. It works fine, apparently, but the injection of any other object from the external dependency that was annotated as a bean doesn't get injected anywhere. Quarkus doesn't seem to recognize it.

Is this some kind of limitation with the Spring DI Extention? I already tried to use the quarkus.index-dependency property and also tried to include the dependency structured as a Quarkus Extention, but it didn't work.

EDIT 1: As stated by @Kolossus, adding the beans.xml resolved the DI issue, but i'm having another error related to the properties class:

java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors

        [error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: Found 3 deployment problems: 
[1] Ambiguous dependencies for type com.properties.IntegrationProperties and qualifiers [@Default]
        - java member: com.authorization.AuthenticationService#<init>()
        - declared on CLASS bean [types=[com.authorization.AuthenticationService, java.lang.Object], qualifiers=[@Named(value = "authenticationService"), @Default, @Any], target=com.authorization.AuthenticationService]
        - available beans:
                - CLASS bean [types=[com.properties.IntegrationProperties, java.lang.Object], qualifiers=[@Default, @Any], target=com.properties.IntegrationProperties]
                - PRODUCER METHOD bean [types=[com.properties.IntegrationProperties, java.lang.Object], qualifiers=[@Default, @Any], target=com.properties.IntegrationProperties produceIntegrationProperties(org.eclipse.microprofile.config.Config), declaringBean=io.quarkus.arc.runtime.config.ConfigPropertiesProducer]

Ambiguous dependencies in all the Injection Points for the properties class.

1 Answers

Adding the beans.xml to the dependency solved my problem. The problem with the properties class was that the class was annotated like this:

@Configuration @ConfigurationProperties(prefix = "some-prefix") public class IntegrationProperties

So Quarkus was creating 2 beans of the same type, one because of the @configuration and the other because of the @ConfigurationProperties. I fixed it by adding @EnableConfigurationProperties(IntegrationProperties.class) in another configuration class.

Related