我需要能够在src|main|java|dbConnection.properties
中存储数据库配置属性,并以jstl表达式的形式将它包含到hibernate.cfg.xml
。 (如:$ {密码}等)。怎么做?如何将外部文件的属性包含到hibernate.cfg.xml中?
当前的hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.username">postgres</property>
<property name="connection.password">postgres</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
</session-factory>
</hibernate-configuration>
我需要的是这样的:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">${DRIVER}</property>
<property name="connection.username">${USERNAME}</property>
<property name="connection.password">${PASSWORD}</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
</session-factory>
</hibernate-configuration>
如果您在使用Spring为什么连打扰一个hibernate.cfg.xml。在春季配置'SessionFactory'并让Spring为您替换占位符。 –