无状态CDI托管bean

时间:2013-04-01 16:43:39

标签: jsf jsf-2 ejb cdi

当我部署一个具有jsf 2.2的WAR文件时,我无法在jboss上找到一个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>

1 个答案:

答案 0 :(得分:2)

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

  

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

     
      
  • 未使用EJB组件定义注释或在 ejb-jar.xml中声明为EJB bean类
  •