问题
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