简体   繁体   English

没有 bean 有资格注入到注入点[JSR-365 5.2.2]

[英]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.大多数时候,我在基于 MicroProfile 的微服务中使用 @Inject 注释,我得到“没有 bean 有资格注入到注入点 [JSR-365 5.2.2]”作为警告。 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].现在在 @Inject 注释处,它显示一个警告标志,其中包含建议-没有 bean 有资格注入到注入点 [JSR-365 5.2.2]。

I am using Microprofile version 3.3 with wildfly 19.1 as run time.我正在使用带有 Wildfly 19.1 的 Microprofile 3.3 版作为运行时。

Note: By adding @SuppressWarnings("cdi-ambiguous-dependency"), it's gone, but it didn't make sense.注意:通过添加@SuppressWarnings("cdi-ambiguous-dependency"),它消失了,但它没有意义。

I assume that's an issue of the IDE you are using.我认为这是您使用的 IDE 的问题 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.由于 Eclipse MicroProfile Config 使用众所周知的 CDI 注释,如@Inject ,您的 IDE 尝试为您提供检查是否有可注入的 CDI bean 的支持。 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. IDE 的这种 CDI 支持可能无法识别您实际上使用的是 Eclipse MicroProfile,因此经典的 CDI 支持认为您想要注入另一个 bean 而不是属性。

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.如果您在运行时没有遇到任何问题,并且只有您在抱怨 IDE,请更新 IDE(如果它支持 MicroProfile 配置)或忽略/抑制此警告。

I'm using IntelliJ IDEA 2020.2 and I don't encounter such issues while developing applicaitons with Eclipse MicroProfile Config.我正在使用 IntelliJ IDEA 2020.2,并且在使用 Eclipse MicroProfile Config 开发应用程序时没有遇到此类问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM