javax.naming.NameNotFoundException: JpaFactory -- service jb



当我从我的web应用程序执行按钮时,我有以下错误:

01:25:04,191 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (http--0.0.0.0-8180-1) #{login.verify}: java.lang.RuntimeException: javax.naming.NameNotFoundException: JpaFactory -- service jboss.naming.context.java.JpaFactory: javax.faces.FacesException: #{login.verify}: java.lang.RuntimeException: javax.naming.NameNotFoundException: JpaFactory -- service jboss.naming.context.java.JpaFactory
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.component.UICommand.broadcast(UICommand.java:315) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final-RECOMPILE.jar:7.1.1.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
    at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
Caused by: javax.faces.el.EvaluationException: java.lang.RuntimeException: javax.naming.NameNotFoundException: JpaFactory -- service jboss.naming.context.java.JpaFactory
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) [jsf-impl-2.1.7-jbossorg-2.jar:]
    ... 20 more
Caused by: java.lang.RuntimeException: javax.naming.NameNotFoundException: JpaFactory -- service jboss.naming.context.java.JpaFactory
    at impl.sdi.persistence.Jpa.jndiFind(Jpa.java:40) [classes:]
    at impl.sdi.persistence.Jpa.getEmf(Jpa.java:27) [classes:]
    at impl.sdi.persistence.Jpa.createEntityManager(Jpa.java:16) [classes:]
    at impl.sdi.business.JpaCommandExecutor.execute(JpaCommandExecutor.java:17) [classes:]
    at impl.sdi.business.SimpleAlumnoService.findAlumnoByUsuario(SimpleAlumnoService.java:49) [classes:]
    at impl.sdi.business.SimpleLoginService.validLogin(SimpleLoginService.java:29) [classes:]
    at impl.sdi.business.SimpleLoginService.verify(SimpleLoginService.java:22) [classes:]
    at com.sdi.presentation.BeanLogin.verify(BeanLogin.java:49) [classes:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_25]
    at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_25]
    at org.apache.el.parser.AstValue.invoke(AstValue.java:262) [jbossweb-7.0.13.Final.jar:]
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) [jbossweb-7.0.13.Final.jar:]
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    ... 21 more
Caused by: javax.naming.NameNotFoundException: JpaFactory -- service jboss.naming.context.java.JpaFactory
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
    at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:113)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
    at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_25]
    at impl.sdi.persistence.Jpa.jndiFind(Jpa.java:37) [classes:]
    ... 36 more

我认为这个问题是由于无法访问EntityManagerFactory而产生的。persistence.xml是下一个:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">
    <persistence-unit name="gestionalumnos" transaction-type="JTA">
        <jta-data-source>java:jboss/datasources/NotaneitorDS</jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
            <property name="jboss.entity.manager.factory.jndi.name" value="java:/JpaFactory"/>
        </properties>
    </persistence-unit>
</persistence>

负责获取EntityManager的类是Jpa.java:

package impl.sdi.persistence;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
public class Jpa {
    private static EntityManagerFactory emf = null;
    private static ThreadLocal<EntityManager> emThread = 
        new ThreadLocal<EntityManager>();
    public static EntityManager createEntityManager() {
        EntityManager entityManager = getEmf().createEntityManager();
        emThread.set(entityManager);
        return entityManager;
    }
    public static EntityManager getManager() {
        return emThread.get();
    }
    public static EntityManagerFactory getEmf() {
        if (emf == null){
            emf = jndiFind("java:/JpaFactory");
        }
        return emf;
    }
    private static EntityManagerFactory jndiFind(String name) {
        Context ctx;
        try {
            ctx = new InitialContext();
            return (EntityManagerFactory) ctx.lookup(name);
        } catch (NamingException e) {
            throw new RuntimeException(e);
        }
    }
}

我想知道我是否做得很好,或者相反,我必须修复一些代码行。

由于将META-INF(包含persistence.xml)放在错误的目录(/WebContent)中而导致的错误。

相关内容

  • 没有找到相关文章

最新更新