javajbosswildflymicroprofileeclipse-microprofile-config

No bean is eligible for injection to the injection point[JSR-365 5.2.2]


Most of the time I use @Inject annotation in MicroProfile based microservices I get "No bean is eligible for injection to the injection point[JSR-365 5.2.2]" as a warning. What is the reason for this warning and what can be done in order to overcome it? Say for example. I wrote a code for property file injection-

@Path("/configProperty")
@Singleton
public class ConfigPropertyResource{
    
    @Inject
    @ConfigProperty(name = "username")
    private String username;

    @GET
    @Path("/mp-config")
    @Produces(MediaType.APPLICATION_JSON)
    public Response mpConfig() {
        Map<String, Object> configProperties = new HashMap<>();
        return Response.ok(configProperties).build();
    }
}

Now at @Inject annotation, it shows a warning sign with the suggestion-No bean is eligible for injection to the injection point[JSR-365 5.2.2].

I am using Microprofile version 3.3 with wildfly 19.1 as run time.

Note: By adding @SuppressWarnings("cdi-ambiguous-dependency"), it's gone, but it didn't make sense.


Solution

  • I assume that's an issue of the IDE you are using. As Eclipse MicroProfile Config uses the well-known CDI annotations like @Inject, your IDE tries to provide you support for checking if there is a CDI bean available to inject. This CDI support of the IDE might not recognize that you actually use Eclipse MicroProfile and hence the classic CDI support is thinking you want to inject another bean but not a property.

    If you don't encounter any issue during runtime and it's just you IDE that's complaining, either update the IDE (if it supports MicroProfile Config) or ignore/suppress this warning.

    I'm using IntelliJ IDEA 2020.2 and I don't encounter such issues while developing applicaitons with Eclipse MicroProfile Config.