我需要能夠在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爲您替換佔位符。 –