meletakkan database properties di luar war

Aplikasi menggunakan framework ZK + Hibernate + Spring, pada applicationContext.xml mengakses file database.properties yang berisi property koneksi ke database. Bagaimana menaruh file database.properties ini di luar folder project atau di luar WAR. Sebagai contoh file database.properties diletakkan pada /home/glassfish/ZKGLASS/

q>Bean untuk mengakses file database.properties

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:/home/glassfish/ZKGLASS/database.properties" />
</bean>

q>Bean yang membaca property file database.properties

<bean id="dataSource"    destroy-method="close">
<property name="driverClass" value="${jdbc.driverClass}" />
<property name="jdbcUrl" value="${jdbc.jdbcUrl}" />
<property name="user" value="${jdbc.user}" />
<property name="password" value="${jdbc.password}" />
</bean>

q>File database.properties

jdbc.driverClass=oracle.jdbc.driver.OracleDriver
jdbc.jdbcUrl=jdbc:oracle:thin:@192.168.56.2:1521:myoracle
jdbc.user=myuser
jdbc.password=mypassword

q> Sedangkan untuk file database.properties yang diletakkan pada WAR, example ditaruh di /WEB-INF/database.properties, maka

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/database.properties" />
</bean>

End ::

Published by

saifiahmada

Begin a big Process with a bit trying

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s