how can i using openshift environment variables in hibernate.cfg.xml

别来无恙 提交于 2019-12-12 04:24:12

问题


I am using Hibernate on OpenShift now.

In hibernate.cfg.xml

When I use:

<property name="connection.url">jdbc:mysql://10.143.140.62:52016/yoodp</property>

It works.

But when I use:

<property name="connection.url">jdbc:mysql://${env.OPENSHIFT_MYSQL_DB_HOST}:${env.OPENSHIFT_MYSQL_DB_PORT}/${env‌​.OPENSHIFT_APP_NAME}</property>

or

<property name="connection.url">jdbc:mysql://${OPENSHIFT_MYSQL_DB_HOST}:${OPENSHIFT_MYSQL_DB_PORT}/${OPENSHIFT_APP_NAME}</property>

It doesn't work.

How can I fix it?


回答1:


I'm guessing you're using Openshift Tomcat, so to connect to your MySQL database simply use the datasource that is already defined for you.

The JNDI datasource is named jdbc/MySQLDS and you use it in hibernate with the connection.datasource property.

https://help.openshift.com/hc/en-us/articles/202399720-How-to-use-the-pre-configured-MySQLDS-and-PostgreSQLDS-data-sources-in-the-Java-cartridges




回答2:


${env.OPENSHIFT_MYSQL_DB_HOST}:${env.OPENSHIFT_MYSQL_DB_PORT}/${env‌​.OPENSHIFT_APP_NAME}

these are the OpesnShift variables. you cant use them for configuration. They should be replaced by their real values which you have done for the first one.



来源:https://stackoverflow.com/questions/27940467/how-can-i-using-openshift-environment-variables-in-hibernate-cfg-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!