初始化CDI Bean名称不明确

时间:2017-03-15 21:42:04

标签: jsf weblogic cdi

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

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

import javax.enterprise.context.ApplicationScoped;

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

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

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也如下:

<?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;

非常感谢任何有关解决此问题的提示。

1 个答案:

答案 0 :(得分:0)

我最终能够部署。

但是,我必须从EAR中删除WAR并单独部署它。出于某种原因,在EAR中打包WAR并进行部署失败。不确定这是WebLogic或EAR配置的问题。