2017-07-09 1 views
0

Hallo ich habe eine Java - Webanwendung entwickelt in Eclipse, ich folge den Tutorials für die Bereitstellung auf Heroku mit Webapp Runner Plugin aber aus irgendeinem Grund, wenn ich versuche, die Seite zu laden (durch Eingabe der URL in einem Browser) die Seite abstürzt, weil es eine ExceptionInitializerError - Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named default wirft. Ich habe in jedem Stack-Overflow-Post und allem, was ich gefunden habe, gesucht und kann keine Lösung finden, da es nicht viele Informationen zur Bereitstellung einer App auch ohne Spring gibt.Heroku JPA ohne Spring Kein Persistence Provider Ausnahme

2017-07-07T11:17:01.000000+00:00 app[api]: Build started by user ... 
2017-07-07T11:17:25.294561+00:00 app[api]: Release v58 created by user ... 
2017-07-07T11:17:25.294561+00:00 app[api]: Deploy d8b63878 by user ... 
2017-07-07T11:17:01.000000+00:00 app[api]: Build succeeded 
2017-07-07T11:17:30.911310+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port 12449 target/*.war` 
2017-07-07T11:17:32.605979+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them. 
2017-07-07T11:17:32.608981+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx350m -Xss512k -Dfile.encoding=UTF-8 
2017-07-07T11:17:33.084080+00:00 app[web.1]: Expanding MissingDog-0.0.1-SNAPSHOT.war into /app/target/tomcat.12449/webapps/expanded 
2017-07-07T11:17:33.084141+00:00 app[web.1]: Adding Context for /app/target/tomcat.12449/webapps/expanded 
2017-07-07T11:17:33.348108+00:00 app[web.1]: Jul 07, 2017 11:17:33 AM org.apache.coyote.AbstractProtocol init 
2017-07-07T11:17:33.348119+00:00 app[web.1]: INFO: Initializing ProtocolHandler ["http-nio-12449"] 
2017-07-07T11:17:33.371914+00:00 app[web.1]: Jul 07, 2017 11:17:33 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector 
2017-07-07T11:17:33.371917+00:00 app[web.1]: INFO: Using a shared selector for servlet write/read 
2017-07-07T11:17:33.375237+00:00 app[web.1]: Jul 07, 2017 11:17:33 AM org.apache.catalina.core.StandardService startInternal 
2017-07-07T11:17:33.375240+00:00 app[web.1]: INFO: Starting service Tomcat 
2017-07-07T11:17:33.376247+00:00 app[web.1]: Jul 07, 2017 11:17:33 AM org.apache.catalina.core.StandardEngine startInternal 
2017-07-07T11:17:33.376248+00:00 app[web.1]: INFO: Starting Servlet Engine: Apache Tomcat/8.5.11 
2017-07-07T11:17:33.566688+00:00 app[web.1]: Jul 07, 2017 11:17:33 AM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment 
2017-07-07T11:17:33.566691+00:00 app[web.1]: INFO: No global web.xml found 
2017-07-07T11:17:34.549303+00:00 heroku[web.1]: State changed from starting to up 
2017-07-07T11:17:35.364701+00:00 app[web.1]: Jul 07, 2017 11:17:35 AM org.apache.jasper.servlet.TldScanner scanJars 
2017-07-07T11:17:35.364725+00:00 app[web.1]: INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 
2017-07-07T11:17:35.491248+00:00 app[web.1]: Jul 07, 2017 11:17:35 AM org.apache.catalina.core.StandardContext listenerStart 
2017-07-07T11:17:35.491252+00:00 app[web.1]: SEVERE: Exception sending context initialized event to listener instance of class com.controllers.MissingDogListener 
2017-07-07T11:17:35.491257+00:00 app[web.1]: java.lang.ExceptionInInitializerError 
2017-07-07T11:17:35.491258+00:00 app[web.1]: at com.missingdog.util.JPAUtil.buildEntityManagerFactory(JPAUtil.java:19) 
2017-07-07T11:17:35.491260+00:00 app[web.1]: at com.controllers.MissingDogListener.contextInitialized(MissingDogListener.java:46) 
2017-07-07T11:17:35.491262+00:00 app[web.1]: at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727) 
2017-07-07T11:17:35.491263+00:00 app[web.1]: at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189) 
2017-07-07T11:17:35.491264+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
2017-07-07T11:17:35.491265+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) 
2017-07-07T11:17:35.491265+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) 
2017-07-07T11:17:35.491266+00:00 app[web.1]: at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
2017-07-07T11:17:35.491267+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
2017-07-07T11:17:35.491267+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
2017-07-07T11:17:35.491268+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:745) 
2017-07-07T11:17:35.491269+00:00 app[web.1]: Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named default 
2017-07-07T11:17:35.491270+00:00 app[web.1]: at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61) 
2017-07-07T11:17:35.491270+00:00 app[web.1]: at com.missingdog.util.JPAUtil.buildEntityManagerFactory(JPAUtil.java:17) 
2017-07-07T11:17:35.491271+00:00 app[web.1]: ... 10 more 
2017-07-07T11:17:35.491272+00:00 app[web.1]: 
2017-07-07T11:17:35.491711+00:00 app[web.1]: Jul 07, 2017 11:17:35 AM org.apache.catalina.core.StandardContext startInternal 
2017-07-07T11:17:35.491712+00:00 app[web.1]: SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file 
2017-07-07T11:17:35.507783+00:00 app[web.1]: Jul 07, 2017 11:17:35 AM org.apache.catalina.core.StandardContext startInternal 
2017-07-07T11:17:35.507786+00:00 app[web.1]: SEVERE: Context [] startup failed due to previous errors 
2017-07-07T11:17:35.508704+00:00 app[web.1]: SEVERE: Context [] failed in [org.apache.catalina.core.StandardContext] lifecycle. Allowing Tomcat to shutdown. 
2017-07-07T11:17:35.520378+00:00 app[web.1]: Jul 07, 2017 11:17:35 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc 
2017-07-07T11:17:35.520385+00:00 app[web.1]: WARNING: The web application [ROOT] registered the JDBC driver [org.postgresql.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 
2017-07-07T11:17:35.527543+00:00 app[web.1]: Jul 07, 2017 11:17:35 AM org.apache.coyote.AbstractProtocol start 
2017-07-07T11:17:35.527545+00:00 app[web.1]: INFO: Starting ProtocolHandler [http-nio-12449] 
2017-07-07T11:17:35.533776+00:00 app[web.1]: Jul 07, 2017 11:17:35 AM org.apache.coyote.AbstractProtocol pause 
2017-07-07T11:17:35.533779+00:00 app[web.1]: INFO: Pausing ProtocolHandler ["http-nio-12449"] 
2017-07-07T11:17:36.028977+00:00 heroku[web.1]: Process exited with status 0 
2017-07-07T11:17:36.041958+00:00 heroku[web.1]: State changed from up to crashed 
2017-07-07T11:17:36.043441+00:00 heroku[web.1]: State changed from crashed to starting 

Hier meine persistence.xml (die in Java Resources -> src -> META-INF -> persistence.xml ist):

Hier wird der Stacktrace ist

<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="default"> 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 
     <exclude-unlisted-classes>false</exclude-unlisted-classes> 
     <properties> 
      <!-- <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> 
      <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/> 
      <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://ec2-23-23-234-118.compute-1.amazonaws.com:5432/d5rinm9divug9g"/> 
      <property name="javax.persistence.jdbc.user" value="ildtjrmqyjqoam"/> 
      <property name="javax.persistence.jdbc.password" value="5a121318dbe1dccaeb88b5cc1085f6c80745aa615fa69c49c19aef6b12469b2e"/> --> 

      <property name="hibernate.archive.autodetection" value="class"/> 
      <property name="hibernate.format_sql" value="true"/> 
      <property name="hibernate.show_sql" value="true"/> 
      <property name="hibernate.hbm2ddl.auto" value="validate"/> 
     </properties> 
    </persistence-unit> 
</persistence> 

Und mein ServletContextListener:

package com.controllers; 

import java.util.HashMap; 
import java.util.Map; 
import java.util.StringTokenizer; 

import javax.servlet.ServletContextEvent; 
import javax.servlet.ServletContextListener; 
import javax.servlet.annotation.WebListener; 

import com.missingdog.util.JPAUtil; 

@WebListener 
public class MissingDogListener implements ServletContextListener { 

    public MissingDogListener() { 

    } 

    public void contextDestroyed(ServletContextEvent arg0) { 
     try { 
      JPAUtil.shutdown(); 
     } catch (Exception e) { 
      throw new ExceptionInInitializerError(e); 
     } 
    } 

    public void contextInitialized(ServletContextEvent arg0) { 
     try { 
      String databaseUrl = System.getenv("DATABASE_URL"); 
      StringTokenizer st = new StringTokenizer(databaseUrl, ":@/"); 
      @SuppressWarnings("unused") 
      String dbVendor = st.nextToken(); //if DATABASE_URL is set 
      String userName = st.nextToken(); 
      String password = st.nextToken(); 
      String host = st.nextToken(); 
      String port = st.nextToken(); 
      String databaseName = st.nextToken(); 
      String jdbcUrl = String.format("jdbc:postgresql://%s:%s/%s?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory", host, port, databaseName); 
      Map<String, String> properties = new HashMap<String, String>(); 
      properties.put("javax.persistence.jdbc.url", jdbcUrl); 
      properties.put("javax.persistence.jdbc.user", userName); 
      properties.put("javax.persistence.jdbc.password", password); 
      properties.put("javax.persistence.jdbc.driver", "org.postgresql.Driver"); 
      properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect"); 
      JPAUtil.buildEntityManagerFactory("default", properties); 
     } catch (Exception e) { 
      throw new ExceptionInInitializerError(e); 
     } 
    } 
} 

Ich hoffe, Sie können hilf mir, eine Lösung zu finden. Danke im Voraus.

+0

Wenn diejenigen Real Benutzername und Passwort sind, müssen Sie 'Heroku pg auszuführen: Anmeldeinformationen: rotate' jetzt. – codefinger

+0

Ich verstehe den Kommentar nicht ... der Benutzer und das Passwort rotieren automatisch ... so bekomme ich sie in Laufzeit –

Antwort

0

Stellen Sie sicher, dass Sie die Postgres Fahrer haben in Ihrem pom.xml:

<dependency> 
    <groupId>org.postgresql</groupId> 
    <artifactId>postgresql</artifactId> 
    <version>9.4-1201-jdbc41</version> 
</dependency> 
+0

Ja, ich habe den Postgres-Treiber in meiner pom.xml –

Verwandte Themen