2012-02-07 62 views
0

原始问题是由于混合CDI和EJB,现在已经解决了这个问题。但以下是使用EJB注释代替Inject后的问题。当依赖的EJB bean注释为@EJB时,JSF无法加载

============================== ========编辑 - 新信息============

看来,JSFServlet无法在加载登录时找到ejb bean'tauthenticator'。 XHTML。另外,当我查看Jboss管理控制台中的jmx bean时,该名称被注册为“Tauthenticator”而不是“tauthenticator”。我不知道这是否是一个问题,认为需要

豆正在创建

21:09:42,602 INFO [org.jboss.ejb3.nointerface.impl.jndi.AbstractNoInterfaceViewBinder] Binding the following entry in Global JNDI for bean:Tauthenticator 
     Tauthenticator/no-interface -> EJB3.1 no-interface view 
[org.jboss.ejb3.nointerface.impl.jndi.AbstractNoInterfaceViewBinder] Binding the following entry in Global JNDI for bean:TusersBean 
     TusersBean/no-interface -> EJB3.1 no-interface view 

部分堆栈跟踪管理bean的tauthenticator“访问http://localhost:8080/timesheet/login.html时:Tauthenticator

javax.servlet.ServletException 
javax.faces.webapp.FacesServlet.service(FacesServlet.java:321) 
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67) 
root cause 

java.lang.StackOverflowError 
java.lang.String.toLowerCase(String.java:2496) 
javax.naming.NameImpl.toBoolean(NameImpl.java:202) 
javax.naming.NameImpl.getBoolean(NameImpl.java:198) 
javax.naming.NameImpl.recordNamingConvention(NameImpl.java:231) 
javax.naming.NameImpl.<init>(NameImpl.java:254) 
javax.naming.NameImpl.<init>(NameImpl.java:291) 
javax.naming.CompoundName.<init>(CompoundName.java:168) 
javax.naming.CompoundName.clone(CompoundName.java:260) 
org.jnp.interfaces.NamingContext.composeName(NamingContext.java:1078) 
org.jnp.interfaces.NamingContext.getAbsoluteName(NamingContext.java:1931) 
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:719) 
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688) 
sun.reflect.GeneratedMethodAccessor411.invoke(Unknown Source) 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
java.lang.reflect.Method.invoke(Method.java:597) 
org.jboss.ejb3.EJBContainer$1.invoke(EJBContainer.java:978) 
$Proxy459.lookup(Unknown Source) 
org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44) 

提取物

@StatefulTimeout(unit=TimeUnit.MINUTES, value=500) @Stateful 
@Named("tauthenticator") public class Tauthenticator { 
@Getter @Setter private String username; 
@Getter @Setter private String password; 
@Getter @Setter boolean loggedIn = false; 
@Getter @Setter Tusers users = null; 
@EJB TusersBean usersBean; 
@Inject private Event<ExceptionToCatch> catchEvent; 

public String authenticate() { 

来自login.xhtml的摘录

<h:outputLabel for="username" style="font-weight:bold;">#{' '}Username</h:outputLabel> 
<p:inputText id="username" value="#{tauthenticator.username}"/> 
<h:outputLabel for="password" style="font-weight:bold;">#{' '}Password</h:outputLabel> 
<p:password id="password" value="#{tauthenticator.password}" feedback="false"/> 
<h:outputLabel>#{''}</h:outputLabel> 
+0

你能展示bean的代码(包括导入)吗? – perissf 2012-02-07 18:27:28

+0

我已经加入 – Rag 2012-02-07 22:21:44

回答

0

你混合CDI(通过javax.enterprise.context.RequestScoped进口)在同一个bean和EJB(通过javax.ejb.Stateful)。而且,这些注释的范围完全不同,因此您应该决定使用哪个范围。而且您应该决定是否要使用Enterprise Java Bean或CDI Bean。

+0

感谢您的回答。从您的解释和其他文档的公平阅读中,我认为ejb(如无状态,有状态或单例标识)作为另一类中的依赖关系引用时,建议使用'@EJB'而不是'@Inject'。我试图使用这个原则,并在我的应用程序中对类进行更改。现在,当我部署应用程序(打包成war)时,它部署得很好。 Jboss报告标记有ejb注释的bean是创建的,并通过JNDI注册。但是当我启动UI时,我得到了stackoverflow异常。我会在 – Rag 2012-02-13 21:37:58

+0

之下解释详细信息和代码,因为我可以在这里输入的字符不多,我会将详细信息添加到原始帖子... – Rag 2012-02-13 21:38:43