【问题标题】:Stateless CDI Managed bean无状态 CDI 托管 bean
【发布时间】:2013-04-01 16:43:38
【问题描述】:

当我部署具有 jsf 2.2 的 WAR 文件时,我在 jboss 上的 JNDI 中找不到 bean,我收到以下异常。有谁知道为什么会这样? (bean在JNDI中,我看到Jboss绑定了它,我尝试了各种查找路径)

Deployment "vfs:///C:/jboss-6.1.0.Final/server/all/deploy/web.war" is in error due to the following reason(s): java.lang.RuntimeException: Could not resolve @EJB reference: [EJB Reference: beanInterface 'se.questify.services.entities.ExamServiceBase', beanName 'null', mappedName 'null', lookupName
 'null', owning unit 'AbstractVFSDeploymentContext@1298976756{vfs:///C:/jboss-6.1.0.Final/server/all/deploy/web.war}'] for environment entry: env/ExamService/local in unit AbstractVFSDeploymentContext@1298976756{vfs:///C:/jboss-6.1.0.Final/server/all/deploy/web.war}

部署 ejb.jar 时的 Jboss 堆栈

INFO  [org.jboss.ejb3.nointerface.impl.jndi.AbstractNoInterfaceViewBinder] Binding the following entry in Global JNDI for bean:ExamServiceBase

        ExamServiceBase/no-interface -> EJB3.1 no-interface view

EJB

@Stateless
@Named("examServiceBase")
public class ExamServiceBase{

    public String getHello(){
        return "hello";
    }
}

JSF 代码

<h:body>    
    <h1>JSF 2 Demo</h1>
    <h:form>
        <h:outputLabel value="#{examServiceBase.hello}" />
    </h:form>
</h:body>

【问题讨论】:

    标签: jsf jsf-2 ejb cdi


    【解决方案1】:

    你不能两者兼得。您不能同时拥有@Named 和@Stateless,它们是互斥的。 From Oracle:

    如果满足以下所有条件,则顶级 java 类是托管 bean:

    • 在ejb-jar.xml中没有使用定义EJB组件的注解或声明为EJB bean类

    【讨论】:

    猜你喜欢
    • 2015-04-20
    • 2016-07-09
    • 2013-08-20
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 2013-10-02
    • 2011-12-05
    相关资源
    最近更新 更多