Elastic Beanstalk应用程序中的MySQL连接错误(Tomcat 7)

时间:2013-02-01 00:13:19

标签: mysql jdbc tomcat7 elastic-beanstalk

我目前正在使用64位AmazonLinux服务器为Tomcat 7部署一个maven构建的.war文件到Elastic Beanstalk。但是,由于以下错误,该应用程序运行良好的localhost没有运行(堆栈跟踪底部):

  

javax.naming.NamingException:com.mysql.jdbc.Driver

我正在连接外部Xeround实例。在网上阅读之后,我尝试将我的应用程序的context.xml修改为:

<Resource auth="Container" 
    factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" //<- NOT THERE BEFORE
    driverClassName="com.mysql.jdbc.Driver" 
    logAbandoned="true" 
    maxActive="100" 
    maxIdle="30" 
    maxWait="10000" 
    name="jdbc/xxxx-01292013" 
    password="xxxx" 
    removeAbandoned="true" 
    removeAbandonedTimeout="60" 
    type="javax.sql.DataSource" 
    url="jdbc:mysql://instancexxxx.db.xeround.com:xxxx/xxxx-01292013?   autoReconnect=true"
    username="xxxx-general"/>

是否有其他人在将以前运行的版本上传并使用Elastic Beanstalk Tomcat 7应用程序时遇到问题并找到了让它运行的方法?

我还阅读了this post,但我不知道在Netbeans maven项目中的.ebextensions文件中添加的位置,我不明白它会做什么。谢谢你的帮助。

  

1)注入构造函数时出错,javax.persistence.PersistenceException:[PersistenceUnit:   myapp-persist]无法构建EntityManagerFactory   com.berger.jpa.EntityInitializer。(EntityInitializer.java:12)
  找到com.berger.jpa.EntityInitializer       for com.nexuscop.startup.StartupListener.entityInit(StartupListener.java:40)中的字段   找到com.nexuscop.startup.StartupListener

     

1错误   com.google.inject.internal.Errors.throwProvisionExceptionIfErrorsExist(Errors.java:451)     在   com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:65)     在   com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:944)     在   com.nexuscop.startup.StartupListener。(StartupListener.java:41)     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native   方法)at   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)     在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     at java.lang.reflect.Constructor.newInstance(Constructor.java:532)     在java.lang.Class.newInstance0(Class.java:372)at   java.lang.Class.newInstance(Class.java:325)at   org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:125)     在   org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4715)     在   org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)     在   org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在   org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)     在   org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)     在   org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)     在   org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1099)     在   org.apache.catalina.startup.HostConfig $ DeployDirectory.run(HostConfig.java:1621)     在   java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471)     at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:334)     在java.util.concurrent.FutureTask.run(FutureTask.java:166)at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:603)     在java.lang.Thread.run(Thread.java:679)引起:   javax.persistence.PersistenceException:[PersistenceUnit:   nexuscop-persist]无法构建EntityManagerFactory   org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)     在   org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)     在   javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)     在   javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)     在com.berger.jpa.JpaPersistService.start(JpaPersistService.java:83)     在com.berger.jpa.EntityInitializer。(EntityInitializer.java:14)     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native   方法)at   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)     在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     at java.lang.reflect.Constructor.newInstance(Constructor.java:532)     在   com.google.inject.internal.DefaultConstructionProxyFactory $ 2.newInstance(DefaultConstructionProxyFactory.java:85)     在   com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)     在   com.google.inject.internal.ConstructorBindingImpl $ Factory.get(ConstructorBindingImpl.java:254)     在   com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:53)     在   com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:110)     在   com.google.inject.internal.MembersInjectorImpl $ 1.call(MembersInjectorImpl.java:75)     在   com.google.inject.internal.MembersInjectorImpl $ 1.call(MembersInjectorImpl.java:73)     在   com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)     在   com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:73)     在   com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:60)     ... 23更多引起:org.hibernate.HibernateException:不能   在哪里找到数据源   org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:79)     在   org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:143)     在   org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:51)     在   org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:90)     在   org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)     在   org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)     在   org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)     在   org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)     ... 42更多引起:javax.naming.NamingException:   com.mysql.jdbc.Driver at   org.apache.naming.NamingContext.lookup(NamingContext.java:860)at   org.apache.naming.NamingContext.lookup(NamingContext.java:154)at   org.apache.naming.NamingContext.lookup(NamingContext.java:831)at   org.apache.naming.NamingContext.lookup(NamingContext.java:154)at   org.apache.naming.NamingContext.lookup(NamingContext.java:831)at   org.apache.naming.NamingContext.lookup(NamingContext.java:154)at   org.apache.naming.NamingContext.lookup(NamingContext.java:831)at   org.apache.naming.NamingContext.lookup(NamingContext.java:168)at   org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)at   javax.naming.InitialContext.lookup(InitialContext.java:409)at   org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)

1 个答案:

答案 0 :(得分:1)

目前,许多人似乎无法使用.ebextensions方法工作。这是一个解决方案,只是为了起床和运行。我不会像这样在生产中运行,但是当我对.ebextensions感到沮丧时,我已经用它来进行测试/调试。

您可以将mysql驱动程序直接放在WAR中。如果您使用的是Maven,只需将其添加到pom.xml:

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>

您也可以将其添加到META-INF / context.xml

<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" factory="org.apache.commons.dbcp.BasicDataSourceFactory" type="javax.sql.DataSource" 
      url="jdbc:mysql://XXXXXXX
       ... />

并将其放在pom.xml中(否则找不到BasicDataSourceFactory):

    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>commons-pool</groupId>
        <artifactId>commons-pool</artifactId>
        <version>1.6</version>
    </dependency>

    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>