当依赖EJB bean使用@EJB注释时,JSF无法加载

时间:2012-02-07 14:43:03

标签: java ejb

最初的问题是由于将CDI与EJB混合,现在已经解决了。但是以下是使用EJB注释代替Inject ...后的问题。

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

似乎JSFServlet在加载login.xhtml时无法找到ejb bean,'tauthenticator'。此外,当我在Jboss管理控制台中查看jmx bean时,该名称被注册为“Tauthenticator”而不是“tauthenticator”。我不知道这是否是一个问题,因为视图需要托管bean'tauthenticator'

正在创建Bean

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

访问http://localhost:8080/timesheet/login.html时的部分堆栈跟踪:

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)

Tauthenticator的提取物

@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>

1 个答案:

答案 0 :(得分:0)

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