没有豆子适用于注入点[JSR-365 5.2.2]。

huangapple go评论79阅读模式
英文:

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

问题

大多数时候,在基于MicroProfile的微服务中使用@Inject注解时,我会收到警告信息:“No bean is eligible for injection to the injection point[JSR-365 5.2.2]”。这个警告的原因是什么,以及如何克服它呢?举个例子,我编写了一个用于属性文件注入的代码:

@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();
    }
}

现在,在@Inject注解处,它显示了一个警告标志,建议说:“No bean is eligible for injection to the injection point[JSR-365 5.2.2]”。

我正在使用MicroProfile版本3.3和Wildfly 19.1作为运行时。

注意:通过添加@SuppressWarnings("cdi-ambiguous-dependency"),警告会消失,但这似乎没有意义。

英文:

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(&quot;/configProperty&quot;)
@Singleton
public class ConfigPropertyResource{
	
	@Inject
	@ConfigProperty(name = &quot;username&quot;)
	private String username;

	@GET
	@Path(&quot;/mp-config&quot;)
	@Produces(MediaType.APPLICATION_JSON)
	public Response mpConfig() {
		Map&lt;String, Object&gt; configProperties = new HashMap&lt;&gt;();
		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.

答案1

得分: 1

我假设这是您正在使用的IDE的问题。由于Eclipse MicroProfile Config使用了众所周知的CDI注解,如@Inject,因此您的IDE会尝试为您提供检查是否存在可注入的CDI bean的支持。IDE的这种CDI支持可能无法识别您实际上正在使用Eclipse MicroProfile,因此经典的CDI支持认为您想要注入另一个bean而不是属性。

如果在运行时没有遇到任何问题,只是您的IDE在抱怨,要么更新IDE(如果支持MicroProfile Config),要么忽略/抑制此警告。

我正在使用IntelliJ IDEA 2020.2,开发Eclipse MicroProfile Config应用程序时并没有遇到这样的问题。

英文:

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.

huangapple
  • 本文由 发表于 2020年8月6日 01:35:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63270597.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定