初始化CDI Bean名称不明确 [英] Initializing CDI Bean Name Ambiguous

查看:168
本文介绍了初始化CDI Bean名称不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过WebLogic Application Server在JSF 2.2上运行的Web应用程序。

I have a web application running on JSF 2.2 over WebLogic Application server.

我有一个简单的Java类,并尝试使用CDI将其初始化为ApplicationScoped对象。以下代码可以正常工作并得到部署。

I have a simple java class and trying to initialize it as an ApplicationScoped object using CDI. The below code works fine and gets deployed.

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class AppContext {
    public AppContext() {
    }
}

但是,当我尝试使用 @Named 注释初始化对象时,它却无法部署

However when I try to initialize the object with @Named annotation, it fails to deploy what so ever

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;

@Named
@ApplicationScoped
public class AppContext {
    public AppContext() {
    }
}

异常日志如下:

weblogic.management.DeploymentException: CDI deployment failure:WELD-001414: Bean name is ambiguous. Name appContext resolves to beans: [Managed Bean [class beans.AppContext] with qualifiers [@Default @Any @Named], Managed Bean [class beans.AppContext] with qualifiers [@Default @Any @Named]]:org.jboss.weld.exceptions.DeploymentException:WELD-001414: Bean name is ambiguous. Name appContext resolves to beans: [Managed Bean [class beans.AppContext] with qualifiers [@Default @Any @Named], Managed Bean [class beans.AppContext] with qualifiers [@Default @Any @Named]]
    at org.jboss.weld.bootstrap.Validator.validateBeanNames(Validator.java:641)
    at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:487)
    at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:446)
    at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90)
    at com.oracle.injection.provider.weld.WeldInjectionContainer.start(WeldInjectionContainer.java:150)
    Truncated. see log file for complete stacktrace

另外,WEB-INF\beans.xml如下:

Also WEB-INF\beans.xml is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

正在运行的应用程序:

JDK 1.8 b121;
Mojarra JSF 2.2;
WebLogic 12.2.1.1;

任何解决此问题的提示都值得赞赏。

Any hint on fixing this issue is highly appreciated.

推荐答案

我最终可以部署。

但是,我不得不从EAR中删除WAR并单独部署。由于某些原因,将WAR打包在EAR中并部署失败。不确定这是否与WebLogic或EAR配置有关。

However, I had to remove the WAR from EAR and deploy it separately. For some reason, packaging the WAR in the EAR and deploying fails. Not sure if this is an issue with WebLogic or EAR configuration.

这篇关于初始化CDI Bean名称不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆