Java CDI 部署失败:WELD-001414 Bean 名称不明确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20050266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 22:41:56  来源:igfitidea点击:

CDI deployment failure:WELD-001414 Bean name is ambiguous

javamavencdiglassfish-4weld

提问by bilal

I have an application, which has multiple modules and various dependencies. When I deploy the application on Glassfish 4, I am getting error:

我有一个应用程序,它有多个模块和各种依赖项。当我在 Glassfish 4 上部署应用程序时,出现错误:

org.jboss.weld.exceptions.DeploymentException: WELD-001414 Bean name is ambiguous. 
Name    JerseyClassAnalyzer resolves to beans: [Managed Bean [class org.glassfish.jersey.internal.inject.JerseyClassAnalyzer] 
with qualifiers [@Default @Named @Any], Managed Bean 
[class org.glassfish.jersey.internal.inject.JerseyClassAnalyzer] 
with qualifiers [@Default @Named @Any]]

What can be the cause? I saw already topics about this and the solution was to edit the annotation but this is not my EJB, just a dependency. How can I avoid this exception?

可能是什么原因?我已经看到了关于这个的话题,解决方案是编辑注释,但这不是我的EJB,只是一个依赖。我怎样才能避免这个异常?

I am using Java EE 6 with JDK 1.7 and Glassfish 4.0.

我将 Java EE 6 与 JDK 1.7 和 Glassfish 4.0 一起使用。

采纳答案by Petr Mensik

Glassfish is already having Jerseys libraries packaged for you, so you need add providedscope into your Maven pom.xmlas stated in the docs.

Glassfish 已经为您打包了 Jerseys 库,因此您需要按照文档中的说明将provided范围添加到您的 Mavenpom.xml中。

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0</version>
    <scope>provided</scope>
</dependency>

If you are using any Jersey specific feature, you will need to depend on Jersey directly.

如果您使用任何 Jersey 特定功能,您将需要直接依赖 Jersey。

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>2.4.1</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.4.1</version>
    <scope>provided</scope>
</dependency>

回答by Sekhon

Are you by any chance packaging the Jersey specific libraries in your EAR file. I believe glassfish does provide the Jersey libraries and you do not need to package them.

您是否有机会在您的 EAR 文件中打包 Jersey 特定的库。我相信 glassfish 确实提供了 Jersey 库,您不需要打包它们。

回答by Rafael Pimenta

I think you have two @Named bean class with the same name.

我认为您有两个同名的 @Named bean 类。