2016-07-26 38 views
0

我需要帮助,显示电子书Algaworks的会诊结果的页面。任何帮助将受到欢迎!java.lang.NoClassDefFoundError:无法初始化类financeiro.util.JpaUtil

控制台(日志文件)

jul 25, 2016 10:42:45 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute 
ADVERTÊNCIA: #{consultaLancamentosBean.consultar}: javax.el.PropertyNotFoundException: /ConsultaLancamentos.xhtml @10,65 action="#{consultaLancamentosBean.consultar}": Target Unreachable, identifier 'consultaLancamentosBean' resolved to null 
javax.faces.FacesException: #{consultaLancamentosBean.consultar}: javax.el.PropertyNotFoundException: /ConsultaLancamentos.xhtml @10,65 action="#{consultaLancamentosBean.consultar}": Target Unreachable, identifier 'consultaLancamentosBean' resolved to null 
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) 
    at javax.faces.component.UIViewAction.broadcast(UIViewAction.java:559) 
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) 
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) 
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) 
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) 
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: javax.faces.el.EvaluationException: javax.el.PropertyNotFoundException: /ConsultaLancamentos.xhtml @10,65 action="#{consultaLancamentosBean.consultar}": Target Unreachable, identifier 'consultaLancamentosBean' resolved to null 
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:94) 
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) 
    ... 28 more 
Caused by: javax.el.PropertyNotFoundException: /ConsultaLancamentos.xhtml @10,65 action="#{consultaLancamentosBean.consultar}": Target Unreachable, identifier 'consultaLancamentosBean' resolved to null 
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107) 
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) 
    ... 29 more 

jul 25, 2016 10:42:45 PM com.sun.faces.context.ExceptionHandlerImpl log 
1100: JSF1073: javax.faces.FacesException obtido durante o processamento de INVOKE_APPLICATION 5: UIComponent-ClientId=, Message=#{consultaLancamentosBean.consultar}: javax.el.PropertyNotFoundException: /ConsultaLancamentos.xhtml @10,65 action="#{consultaLancamentosBean.consultar}": Target Unreachable, identifier 'consultaLancamentosBean' resolved to null 
jul 25, 2016 10:42:45 PM com.sun.faces.context.ExceptionHandlerImpl log 
1100: #{consultaLancamentosBean.consultar}: javax.el.PropertyNotFoundException: /ConsultaLancamentos.xhtml @10,65 action="#{consultaLancamentosBean.consultar}": Target Unreachable, identifier 'consultaLancamentosBean' resolved to null 
javax.faces.FacesException: #{consultaLancamentosBean.consultar}: javax.el.PropertyNotFoundException: /ConsultaLancamentos.xhtml @10,65 action="#{consultaLancamentosBean.consultar}": Target Unreachable, identifier 'consultaLancamentosBean' resolved to null 
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:89) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) 
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) 
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: javax.faces.FacesException: #{consultaLancamentosBean.consultar}: javax.el.PropertyNotFoundException: /ConsultaLancamentos.xhtml @10,65 action="#{consultaLancamentosBean.consultar}": Target Unreachable, identifier 'consultaLancamentosBean' resolved to null 
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) 
    at javax.faces.component.UIViewAction.broadcast(UIViewAction.java:559) 
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) 
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) 
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) 
    ... 24 more 
Caused by: javax.faces.el.EvaluationException: javax.el.PropertyNotFoundException: /ConsultaLancamentos.xhtml @10,65 action="#{consultaLancamentosBean.consultar}": Target Unreachable, identifier 'consultaLancamentosBean' resolved to null 
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:94) 
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) 
    ... 28 more 
Caused by: javax.el.PropertyNotFoundException: /ConsultaLancamentos.xhtml @10,65 action="#{consultaLancamentosBean.consultar}": Target Unreachable, identifier 'consultaLancamentosBean' resolved to null 
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107) 
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) 
    ... 29 more 

--->的persistence.xml(/ SRC /主/资源/ META-INF):

<?xml version="1.0" encoding="UTF-8" ?> 
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence 
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" 
    version="2.1"> 

    <persistence-unit name="FinanceiroPU"> 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 
     <class>com.janaina.financeiro.model.Pessoa</class> 
     <class>com.janaina.financeiro.model.Lancamento</class> 

     <properties> 
      <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/financeiro" /> 
      <property name="javax.persistence.jdbc.user" value="postgres" /> 
      <property name="javax.persistence.jdbc.password" value="postgres" /> 
      <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" /> 

      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> 
      <property name="hibernate.show_sql" value="true" /> 
      <property name="hibernate.format_sql" value="true" /> 
      <property name="hibernate.hbm2ddl.auto" value="update" /> 
     </properties> 
    </persistence-unit> 
</persistence> 

---> ConsultaLacamentos.xhtml :

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://xmlns.jcp.org/jsf/core" 
    xmlns:h="http://xmlns.jcp.org/jsf/html"> 
<h:head> 
    <title>Consulta de lançamentos</title> 
</h:head> 
<h:body> 
    <f:metadata> 
     <f:viewAction action="#{consultaLancamentosBean.consultar}" /> 
    </f:metadata> 
    <h1>Consulta de lançamentos</h1> 
    <h:form id="frm"> 
     <h:dataTable value="#{consultaLancamentosBean.lancamentos}" 
      var="lancamento" border="1" cellspacing="0" cellpadding="2"> 
      <h:column> 
       <f:facet name="header"> 
        <h:outputText value="Pessoa" /> 
       </f:facet> 
       <h:outputText value="#{lancamento.pessoa.nome}" /> 
      </h:column> 
      <h:column> 
       <f:facet name="header"> 
        <h:outputText value="Descrição" /> 
       </f:facet> 
       <h:outputText value="#{lancamento.descricao}" /> 
      </h:column> 
      <h:column> 
       <f:facet name="header"> 
        <h:outputText value="Tipo" /> 
       </f:facet> 
       <h:outputText value="#{lancamento.tipo}" /> 
      </h:column> 
      <h:column> 
       <f:facet name="header"> 
        <h:outputText value="Valor" /> 
       </f:facet> 
       <h:outputText value="#{lancamento.valor}" /> 
      </h:column> 
      <h:column> 
       <f:facet name="header"> 
        <h:outputText value="Data de vencimento" /> 
       </f:facet> 
       <h:outputText value="#{lancamento.dataVencimento}" /> 
      </h:column> 
      <h:column> 
       <f:facet name="header"> 
        <h:outputText value="Data de pagamento" /> 
       </f:facet> 
       <h:outputText value="#{lancamento.dataPagamento}" /> 
      </h:column> 
     </h:dataTable> 
    </h:form> 
</h:body> 
</html> 

---> ConsultaLacamentosBean.java

package com.janaina.financeiro.controller; 

import java.io.Serializable; 
import java.util.List; 

import javax.faces.bean.ManagedBean; 
import javax.faces.view.ViewScoped; 
import javax.persistence.EntityManager; 
import javax.persistence.TypedQuery; 

import com.janaina.financeiro.model.Lancamento; 
import com.janaina.financeiro.util.JpaUtil; 

@ManagedBean 
@ViewScoped 
public class ConsultaLancamentosBean implements Serializable { 
    private static final long serialVersionUID = 1L; 
    private List<Lancamento> lancamentos; 

    public void consultar() { 
     EntityManager manager = JpaUtil.getEntityManager(); 
     TypedQuery<Lancamento> query = manager.createQuery("from Lancamento", Lancamento.class); 
     this.lancamentos = query.getResultList(); 
     manager.close(); 
    } 

    public List<Lancamento> getLancamentos() { 
     return lancamentos; 
    } 
} 

---> JpaUtil.java

package com.janaina.financeiro.util; 

import javax.persistence.EntityManager; 
import javax.persistence.EntityManagerFactory; 
import javax.persistence.Persistence; 

//JpaUtil armazena a instância compartilhada de EntityManagerFactory em uma variável estática 
//Qualquer código terá acesso fácil e rápido 
//Sempre que for preciso uma EntityManager basta chamar: 
//EntityManager manager = JpaUtil.getEntityManager(); 

public class JpaUtil { 
    private static EntityManagerFactory factory; 
    static { 
     factory = Persistence.createEntityManagerFactory("FinanceiroPU"); 
    } 

    public static EntityManager getEntityManager() { 
     return factory.createEntityManager(); 
    } 
} 
+0

按照异常跟踪,类JPAUtil尚未成功初始化。我猜这是因为jpa facetory在这里没有创建成功 factory = Persistence.createEntityManagerFactory(“FinanceiroPU”); –

+0

你认为我能做什么? –

+0

实体工厂由于某种原因未正确初始化。你可能会从日志中找出原因,控制台,可能是数据库信息有错字。或者你可以把整个日志文件? –

回答

0

我解决了这个问题!我意识到,我的问题的原因是:

1)我是使用Java JRE,而不是JDK的项目。为了解决这个问题,我做了以下工作:右键单击项目>属性> Java构建路径>库>选择的JRE我正在使用>编辑>已安装的JRE>搜索> JDK路径(C:\ Program Files \ Java \ jdk1.8.0_101 )。

2)然后,我意识到,我是不是能够连接到PostgreSQL。然后我卸载了PostgreSQL,并在Program Files中删除了它的目录,然后我重新安装了!

3)最后:在项目>运行方式>的Maven> Maven的清洁,然后分辩,单击项目>运行方式>的Maven>的Maven分辩单击安装

以上为我工作的步骤。我希望他们帮助别人!

我(web.xml中):

<context-param> 
       <param-name>javax.faces.PROJECT_STAGE</param-name> 
       <param-value>Development</param-value> 
     </context-param> 

     <servlet> 
       <servlet-name>Faces Servlet</servlet-name> 
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
       <load-on-startup>1</load-on-startup> 
     </servlet> 
     <servlet-mapping> 
       <servlet-name>Faces Servlet</servlet-name> 
       <url-pattern>/faces/*</url-pattern> 
     </servlet-mapping> 

的persistence.xml:

<?xml version="1.0" encoding="UTF-8" ?> 
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence 
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" 
     version="2.1"> 

     <persistence-unit name="FinanceiroPU"> 
       <provider>org.hibernate.ejb.HibernatePersistence</provider> 
       <class>com.janaina.financeiro.model.Lancamento</class> 
       <class>com.janaina.financeiro.model.Pessoa</class> 

       <properties> 
         <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/financeiro" /> 
         <property name="javax.persistence.jdbc.user" value="postgres" /> 
         <property name="javax.persistence.jdbc.password" value="postgres" /> 
         <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" /> 

         <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> 
         <property name="hibernate.show_sql" value="true" /> 
         <property name="hibernate.format_sql" value="true" /> 
         <property name="hibernate.hbm2ddl.auto" value="update" /> 
       </properties> 
     </persistence-unit> 
</persistence> 
相关问题