Mysql 部署在ec2上的SpringWAR文件显示连接到rds的hibernate持久性故障

Mysql 部署在ec2上的SpringWAR文件显示连接到rds的hibernate持久性故障,mysql,hibernate,amazon-ec2,tomcat7,rds,Mysql,Hibernate,Amazon Ec2,Tomcat7,Rds,我们公司有一个应用程序已经在media temple上托管,我们现在正在迁移到amazon ec2。我已经阅读了所有教程,apache、php、mysql、java和tomcat7都运行得很好。另外,我已经能够使用mysql workbench连接到rds实例 然而,当我将war文件上传到tomcat管理器时,我得到一个错误,表明它无法连接到数据库 下面是catalina.out文件中错误的顶部 --------------日志文件中的代码片段--------------------------

我们公司有一个应用程序已经在media temple上托管,我们现在正在迁移到amazon ec2。我已经阅读了所有教程,apache、php、mysql、java和tomcat7都运行得很好。另外,我已经能够使用mysql workbench连接到rds实例

然而,当我将war文件上传到tomcat管理器时,我得到一个错误,表明它无法连接到数据库

下面是
catalina.out
文件中错误的顶部

--------------日志文件中的代码片段------------------------------------------

17:28:52.311 [http-bio-8080-exec-1] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy method 'close' on bean with name 'dataSource'
17:28:52.311 [http-bio-8080-exec-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#73e12051': [org.springframework.se
curity.access.method.DelegatingMethodSecurityMetadataSource#0]
17:28:52.311 [http-bio-8080-exec-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#3b35dc09': [(inner bean)#73e12051]
17:28:52.312 [http-bio-8080-exec-1] **ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [/var/lib/tomcat7/webapps/clearbox/WEB
-INF/classes/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit
: persistenceUnit] Unable to build EntityManagerFactory**
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) ~[spring-beans-
4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.0
.3.RELEASE.jar:4.0.3.RELEASE]
Here is the database.properties that holds the info for applicationContext.xml
database.driverClassName=com.mysql.jdbc.Driver
database.url=jdbc\:mysql\://localhost\:3306/clearboxdb
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
database.username=MYUSERNAMEHERE
database.password=MYPASSWORDHERE
。。。。等等……

SEVERE: The web application [/clearbox] 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.

**------------END SNIPPET FROM LOG FILE-----------------------------**

Here is the code from the applicationContext.xml it attempts to run

**--------------SNIPPET FROM applicationContect.xml----------------**

    <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
        <property name="driverClassName" value="${database.driverClassName}"/>
        <property name="url" value="${database.url}"/>
        <property name="username" value="${database.username}"/>
        <property name="password" value="${database.password}"/>
        <property name="testOnBorrow" value="true"/>
        <property name="testOnReturn" value="true"/>
        <property name="testWhileIdle" value="true"/>
        <property name="timeBetweenEvictionRunsMillis" value="1800000"/>
        <property name="numTestsPerEvictionRun" value="3"/>
        <property name="minEvictableIdleTimeMillis" value="1800000"/>
        <property name="validationQuery" value="SELECT 1"/>
    </bean>

    <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
--------------来自数据库的代码段。属性-------------------

17:28:52.311 [http-bio-8080-exec-1] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy method 'close' on bean with name 'dataSource'
17:28:52.311 [http-bio-8080-exec-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#73e12051': [org.springframework.se
curity.access.method.DelegatingMethodSecurityMetadataSource#0]
17:28:52.311 [http-bio-8080-exec-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#3b35dc09': [(inner bean)#73e12051]
17:28:52.312 [http-bio-8080-exec-1] **ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [/var/lib/tomcat7/webapps/clearbox/WEB
-INF/classes/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit
: persistenceUnit] Unable to build EntityManagerFactory**
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) ~[spring-beans-
4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.0
.3.RELEASE.jar:4.0.3.RELEASE]
Here is the database.properties that holds the info for applicationContext.xml
database.driverClassName=com.mysql.jdbc.Driver
database.url=jdbc\:mysql\://localhost\:3306/clearboxdb
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
database.username=MYUSERNAMEHERE
database.password=MYPASSWORDHERE
--------------结束代码段--------------------

17:28:52.311 [http-bio-8080-exec-1] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy method 'close' on bean with name 'dataSource'
17:28:52.311 [http-bio-8080-exec-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#73e12051': [org.springframework.se
curity.access.method.DelegatingMethodSecurityMetadataSource#0]
17:28:52.311 [http-bio-8080-exec-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#3b35dc09': [(inner bean)#73e12051]
17:28:52.312 [http-bio-8080-exec-1] **ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [/var/lib/tomcat7/webapps/clearbox/WEB
-INF/classes/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit
: persistenceUnit] Unable to build EntityManagerFactory**
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) ~[spring-beans-
4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.0
.3.RELEASE.jar:4.0.3.RELEASE]
Here is the database.properties that holds the info for applicationContext.xml
database.driverClassName=com.mysql.jdbc.Driver
database.url=jdbc\:mysql\://localhost\:3306/clearboxdb
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
database.username=MYUSERNAMEHERE
database.password=MYPASSWORDHERE
rds有一个安全组,该安全组具有以下入站功能: MYSQL TCP 3306 0.0.0.0/0

目前,我的本地tomcat7和我们现有的tomcat7 live应用程序上的一切都正常工作。所以我不确定错误在哪里

  • 是否处于ec2/rds安全组级别
  • 它是否处于hibernate/spring持久化级别
  • 它是mysql用户级别的吗
任何人都可以帮助我,或者告诉我一个现有的帖子的答案。我已经在stackoverflow冲浪了几天,决定问这个问题

一个可能有用的提示是,在我们开始使用ec2之前,一个新开发人员在本地部署war时遇到了相同的错误。我们找到了一个解决方案,在他的系统中,只有mysql用户名:root,没有密码,导致war文件工作


因此,现在我再次看到此错误,但我无法在实时系统上设置没有密码的root。

您的数据库url设置为localhost,如果您使用的是RDS,则不是这种情况,而是应该用RDS控制台中提供的主机名替换它(类似于dbname.somerandomchars.rds.eu west…抱歉,我手头没有示例,因此这是从内存中猜测的顺序可能略有不同)。您还需要确保将db用户名和密码设置为rds值


另一件事是,如果您的数据库可以从工作台访问,这是否意味着您选择了“公共访问”如果是这样,您必须更改安全组,允许所有流量是非常不安全的,如果绝对必须是公共的,您应该使用安全组将范围缩小到有限的范围。

mhbooks!!!非常感谢您,我们参加了比赛,一切都得到了正确的回答和完成。这将帮助那些需要帮助的人:)没问题,很高兴你都准备好了