Lacatin
Lacatin

Reputation: 1

Why is Micronaut not able to inject dependencies in my setup?

Im trying to run some BDD tests with Serenity and I need Micronaut for the injection part. The problem is that Micronaut injection does not work for some reason.

I keep getting this error:

io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for parameter [serviceEndpointProvider] of class: {path}.ApiClient

Message: No bean of type [{path}.ServiceEndpointProvider] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
Path Taken: new ApiClient(ServiceEndpointProvider serviceEndpointProvider) --> new ApiClient([ServiceEndpointProvider serviceEndpointProvider])

The serviceEndpointProvider is an interface with 2 implementations, the one needed in my case is this one (keep in mind that this comes from a Micronaut dependency, not created by me):

@Singleton
@Requires(
    missingProperty = "canary.service-endpoint"
)
public class OfflineServiceEndpointProvider implements ServiceEndpointProvider {
    private final String serviceEndpoint;

    public OfflineServiceEndpointProvider(EmbeddedServer embeddedServer) {
        this.serviceEndpoint = embeddedServer.getURI().toString();
    }

    public String endpoint() {
        return this.serviceEndpoint;
    }
}

I do not have this property in my application.properties files and it already has the Singleton annotation. Does anyone have any idea why this could happen?

Upvotes: 0

Views: 48

Answers (0)

Related Questions