Java休眠在本地计算机上运行, 但在Heroku云上失败

问题描述 投票:0回答:1

我在heruko上托管了一个JAVA应用程序,并具有此设置

  • JAVA 1.8
  • 休眠
  • JSF / Primefaces
  • Mysql(JawsDB MySQL)

我能够在JAVA中部署该项目。但是,我很难连接到银行(也来自heroku)

我正在使用休眠模式来坚持到银行

  • hibernate.cfg.xml

编码

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://g8mh6ge01lu2z3n1.cbetxkdyhwsb.us-east-1.rds.amazonaws.com:3306/mro3io1m3qiarize</property>
<property name="hibernate.connection.username">m0pkc0h6eoj9xzgk</property>
<property name="hibernate.connection.password">wctoxqaak6shkt2p</property>

在heroku上部署并运行应用程序后,出现错误消息:

原因:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:由于底层异常,无法加载连接类:'java.lang.NumberFormatException:对于输入字符串:“ wctoxqaak6shkt2p@g8mh6ge01lu2z3n1.cbetxkdyhwsb.us-east-1.rds.amazonaws.com:3306”'

和另一个错误消息:

由:java.lang.NumberFormatException:对于输入字符串:“ wctoxqaak6shkt2p@g8mh6ge01lu2z3n1.cbetxkdyhwsb.us-east-1.rds.amazonaws.com:3306”

e mais outra:

app [web.1]:java.lang.NoClassDefFoundError:无法初始化类br.com.desafiosefaz.util.HibernateUtil

HibernateUtil.java

public class HibernateUtil {


    private static SessionFactory fabricaDeSessoes = criarFabricaDeSessoes(); 

    public static SessionFactory getFabricaDeSessoes() {
        return fabricaDeSessoes;
    }
    private static SessionFactory criarFabricaDeSessoes() {

        try {
            Configuration configuracao = new Configuration().configure(); 

            @SuppressWarnings("unused") 
            ServiceRegistry registro = new StandardServiceRegistryBuilder().applySettings(configuracao.getProperties()).build();
            SessionFactory fabrica = configuracao.buildSessionFactory();
            return fabrica;
        } catch (Exception ex) {
            System.err.println("Não foi possível criar a fábrica de sessões ! erro: " + ex);
            throw new ExceptionInInitializerError(ex);
        }
    } 
}

不记录CMD

C:\Users\ALEXTI\Documents\SELECAO\IVIA\DesafioSefazIvia>heroku logs --app desafiosefazivia
(node:7692) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
2019-11-03T07:05:23.029109+00:00 app[web.1]: at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
2019-11-03T07:05:23.029112+00:00 app[web.1]: at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
2019-11-03T07:05:23.029114+00:00 app[web.1]: at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
2019-11-03T07:05:23.029116+00:00 app[web.1]: at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
2019-11-03T07:05:23.029118+00:00 app[web.1]: at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:94)
2019-11-03T07:05:23.02912+00:00 app[web.1]: at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
2019-11-03T07:05:23.029122+00:00 app[web.1]: ... 41 more
2019-11-03T07:05:23.029125+00:00 app[web.1]: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Cannot load connection class because of underlying exception: 'java.lang.NumberFormatException: For input string: "wctoxqaak6shkt2p@g8mh6ge01lu2z3n1.cbetxkdyhwsb.us-east-1.rds.amazonaws.com:3306"'.
2019-11-03T07:05:23.029127+00:00 app[web.1]: at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
2019-11-03T07:05:23.029129+00:00 app[web.1]: at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
2019-11-03T07:05:23.029131+00:00 app[web.1]: at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
2019-11-03T07:05:23.029133+00:00 app[web.1]: at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
2019-11-03T07:05:23.029135+00:00 app[web.1]: at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
2019-11-03T07:05:23.029137+00:00 app[web.1]: at com.mysql.jdbc.Util.getInstance(Util.java:408)
2019-11-03T07:05:23.029139+00:00 app[web.1]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
2019-11-03T07:05:23.029141+00:00 app[web.1]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
2019-11-03T07:05:23.029143+00:00 app[web.1]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
2019-11-03T07:05:23.029145+00:00 app[web.1]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
2019-11-03T07:05:23.029148+00:00 app[web.1]: at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:338)
2019-11-03T07:05:23.02915+00:00 app[web.1]: at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
2019-11-03T07:05:23.029152+00:00 app[web.1]: ... 56 more
2019-11-03T07:05:23.029159+00:00 app[web.1]: Caused by: java.lang.NumberFormatException: For input string: "wctoxqaak6shkt2p@g8mh6ge01lu2z3n1.cbetxkdyhwsb.us-east-1.rds.amazonaws.com:3306"
2019-11-03T07:05:23.029161+00:00 app[web.1]: at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
2019-11-03T07:05:23.029163+00:00 app[web.1]: at java.lang.Integer.parseInt(Integer.java:580)
2019-11-03T07:05:23.029165+00:00 app[web.1]: at java.lang.Integer.parseInt(Integer.java:615)
2019-11-03T07:05:23.029167+00:00 app[web.1]: at com.mysql.jdbc.NonRegisteringDriver.port(NonRegisteringDriver.java:825)
2019-11-03T07:05:23.029169+00:00 app[web.1]: at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
2019-11-03T07:05:23.029171+00:00 app[web.1]: ... 57 more
2019-11-03T07:05:23.029173+00:00 app[web.1]:
2019-11-03T07:05:23.132051+00:00 app[web.1]: Nov 03, 2019 7:05:23 AM com.sun.faces.config.ConfigureListener contextInitialized
2019-11-03T07:05:23.132063+00:00 app[web.1]: INFO: Initializing Mojarra 2.2.12 ( 20150720-0848 https://svn.java.net/svn/mojarra~svn/tags/2.2.12@14885) for context ''
2019-11-03T07:05:23.664757+00:00 app[web.1]: Nov 03, 2019 7:05:23 AM com.sun.faces.spi.InjectionProviderFactory createInstance
2019-11-03T07:05:23.66477+00:00 app[web.1]: INFO: JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
2019-11-03T07:05:25.003827+00:00 app[web.1]: Nov 03, 2019 7:05:25 AM org.primefaces.webapp.PostConstructApplicationEventListener processEvent
2019-11-03T07:05:25.00384+00:00 app[web.1]: INFO: Running on PrimeFaces 6.0
2019-11-03T07:05:25.005068+00:00 app[web.1]: Nov 03, 2019 7:05:25 AM org.omnifaces.VersionLoggerEventListener processEvent
2019-11-03T07:05:25.005072+00:00 app[web.1]: INFO: Using OmniFaces version 1.11
2019-11-03T07:05:25.006242+00:00 app[web.1]: Nov 03, 2019 7:05:25 AM org.apache.catalina.core.StandardContext startInternal
2019-11-03T07:05:25.006245+00:00 app[web.1]: SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
2019-11-03T07:05:25.020417+00:00 app[web.1]: Nov 03, 2019 7:05:25 AM org.apache.catalina.core.StandardContext startInternal
2019-11-03T07:05:25.020421+00:00 app[web.1]: SEVERE: Context [] startup failed due to previous errors
2019-11-03T07:05:25.021139+00:00 app[web.1]: SEVERE: Context [] failed in [org.apache.catalina.core.StandardContext] lifecycle. Allowing Tomcat to shutdown.
2019-11-03T07:05:25.034249+00:00 app[web.1]: Nov 03, 2019 7:05:25 AM org.apache.catalina.core.StandardContext listenerStop
2019-11-03T07:05:25.034254+00:00 app[web.1]: SEVERE: Exception sending context destroyed event to listener instance of class [br.com.desafiosefaz.util.HibernateContexto]
2019-11-03T07:05:25.034257+00:00 app[web.1]: java.lang.NoClassDefFoundError: Could not initialize class br.com.desafiosefaz.util.HibernateUtil
2019-11-03T07:05:25.034259+00:00 app[web.1]: at br.com.desafiosefaz.util.HibernateContexto.contextDestroyed(HibernateContexto.java:14)
2019-11-03T07:05:25.034261+00:00 app[web.1]: at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4732)
2019-11-03T07:05:25.034263+00:00 app[web.1]: at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5396)
2019-11-03T07:05:25.034265+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
2019-11-03T07:05:25.034267+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:187)
2019-11-03T07:05:25.034269+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
2019-11-03T07:05:25.034271+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
2019-11-03T07:05:25.034274+00:00 app[web.1]: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2019-11-03T07:05:25.034276+00:00 app[web.1]: at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
2019-11-03T07:05:25.034278+00:00 app[web.1]: at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
2019-11-03T07:05:25.03428+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
2019-11-03T07:05:25.034282+00:00 app[web.1]: at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
2019-11-03T07:05:25.034284+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
2019-11-03T07:05:25.034286+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
2019-11-03T07:05:25.034288+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
2019-11-03T07:05:25.034291+00:00 app[web.1]: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2019-11-03T07:05:25.034293+00:00 app[web.1]: at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
2019-11-03T07:05:25.034295+00:00 app[web.1]: at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
2019-11-03T07:05:25.034297+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
2019-11-03T07:05:25.034299+00:00 app[web.1]: at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
2019-11-03T07:05:25.034301+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
2019-11-03T07:05:25.034303+00:00 app[web.1]: at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
2019-11-03T07:05:25.034306+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
2019-11-03T07:05:25.034308+00:00 app[web.1]: at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932)
2019-11-03T07:05:25.03431+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
2019-11-03T07:05:25.034312+00:00 app[web.1]: at org.apache.catalina.startup.Tomcat.start(Tomcat.java:459)
2019-11-03T07:05:25.034314+00:00 app[web.1]: at webapp.runner.launch.Main.main(Main.java:289)
2019-11-03T07:05:25.034316+00:00 app[web.1]:
2019-11-03T07:05:25.047239+00:00 app[web.1]: Nov 03, 2019 7:05:25 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
2019-11-03T07:05:25.047243+00:00 app[web.1]: WARNING: The web application [ROOT] registered the JDBC driver [com.mysql.fabric.jdbc.FabricMySQLDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2019-11-03T07:05:25.048235+00:00 app[web.1]: Nov 03, 2019 7:05:25 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
2019-11-03T07:05:25.048244+00:00 app[web.1]: WARNING: The web application [ROOT] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2019-11-03T07:05:25.066549+00:00 app[web.1]: Nov 03, 2019 7:05:25 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
2019-11-03T07:05:25.066563+00:00 app[web.1]: WARNING: The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
2019-11-03T07:05:25.066567+00:00 app[web.1]: java.lang.Object.wait(Native Method)
2019-11-03T07:05:25.066569+00:00 app[web.1]: java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
2019-11-03T07:05:25.066572+00:00 app[web.1]: com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:64)
2019-11-03T07:05:25.066574+00:00 app[web.1]: java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2019-11-03T07:05:25.066576+00:00 app[web.1]: java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2019-11-03T07:05:25.066578+00:00 app[web.1]: java.lang.Thread.run(Thread.java:748)
2019-11-03T07:05:25.097864+00:00 app[web.1]: Nov 03, 2019 7:05:25 AM org.apache.coyote.AbstractProtocol start
2019-11-03T07:05:25.097868+00:00 app[web.1]: INFO: Starting ProtocolHandler ["http-nio-55905"]
2019-11-03T07:05:27.852362+00:00 app[web.1]: Nov 03, 2019 7:05:27 AM org.apache.catalina.loader.WebappClassLoaderBase checkStateForResourceLoading
2019-11-03T07:05:27.852381+00:00 app[web.1]: INFO: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
2019-11-03T07:05:27.852384+00:00 app[web.1]: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
2019-11-03T07:05:27.852387+00:00 app[web.1]: at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1385)
2019-11-03T07:05:27.852389+00:00 app[web.1]: at org.apache.catalina.loader.WebappClassLoaderBase.getResource(WebappClassLoaderBase.java:1038)
2019-11-03T07:05:27.852391+00:00 app[web.1]: at com.mysql.jdbc.AbandonedConnectionCleanupThread.checkContextClassLoaders(AbandonedConnectionCleanupThread.java:90)
2019-11-03T07:05:27.852394+00:00 app[web.1]: at com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:63)
2019-11-03T07:05:27.852396+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2019-11-03T07:05:27.852398+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2019-11-03T07:05:27.852401+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:748)
2019-11-03T07:05:27.852403+00:00 app[web.1]:

heroku上的Mysql版本

enter image description here

pom.xml中的Mysql版本

mysqlMySQL的连接器的Java8.0.11

我在本地可以访问银行并执行查询和插入操作:

enter image description here

Heroku中的错误

enter image description here

Infor应用程序:

enter image description here

java mysql hibernate heroku java-ee
1个回答
0
投票

早安,

[请问,有人在使用springboot和mysql驱动程序遇到相同的问题时,是否设法解决了此问题?似乎mysql驱动程序不喜欢heroku数据库连接字符串的格式,因为它包含冒号“:”后的字符,而不是数字,通常是端口号。]

有人可以帮忙!

谢谢,

© www.soinside.com 2019 - 2024. All rights reserved.