Openshift上的MySQL连接Tomcat 7 [英] Mysql connection Tomcat 7 on Openshift
问题描述
我在openshift服务器(tomcat,mysql)上部署了应用程序,但无法连接数据库(我使用phpmyadmin创建数据库和表).在我的本地主机上,一切正常.这是我的坚持:
I deployed application on openshift server (tomcat, mysql) but I can't connect with my db (I use phpmyadmin to create db and tables). On my localhost everythings work well. Here is my persistence:
<persistence version="2.0" 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">
<persistence-unit name="eshopPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>foo.domain.Catalog</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/katalog"/>
<property name="javax.persistence.jdbc.password" value="dyfghd"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="abyrewef"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
服务器日志: org.springframework.beans.factory.BeanCreationException:创建名称为"katalogDAO"的bean时出错:自动连接依赖项的注入失败;嵌套的异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:foo.repositories.KatalogRepository foo.repositories.KatalogDAO.katalogRepository;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'katalogRepository'的bean时出错:持久性依赖项注入失败;嵌套的异常是javax.persistence.PersistenceException:异常[EclipseLink-4002](Eclipse Persistence Services-2.3.2.v20111125-r10461):org.eclipse.persistence.exceptions.DatabaseException 内部异常:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败
server logs: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'katalogDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: foo.repositories.KatalogRepository foo.repositories.KatalogDAO.katalogRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'katalogRepository': Injection of persistence dependencies failed; nested exception is javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
我不知道怎么了.感谢您的帮助.
I don't know what is wrong. Thanks for help.
推荐答案
好,我解决了这个问题.在persistance.xml和spring配置文件中,我插入了用户和密码(属性),就像在openshift上在数据库连接中输入的一样.在网址属性中,我输入了:
Ok I solved the issue. In persistance.xml and spring configuration file I inserted the user and password (properties) the same like I had in my db connection on openshift. In url propertie I put :
value="jdbc:mysql://${OPENSHIFT_MYSQL_DB_HOST}:${OPENSHIFT_MYSQL_DB_PORT}/${OPENSHIFT_APP_NAME}"
并且工作正常(我使用的是tomcat 7和mysql 5.1,基于spring 3和thymeleaf的应用程序.)
and works fine (I use tomcat 7 and mysql 5.1, app based on spring 3 and thymeleaf).
这篇关于Openshift上的MySQL连接Tomcat 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!