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
[sourcecode language="xml"]
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:/home/glassfish/ZKGLASS/database.properties" />
</bean>[/sourcecode]
q>Bean yang membaca property file database.properties
[sourcecode language="xml"]
<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>
[/sourcecode]
q>File database.properties
[sourcecode language="xml"]
jdbc.driverClass=oracle.jdbc.driver.OracleDriver
jdbc.jdbcUrl=jdbc:oracle:thin:@192.168.56.2:1521:myoracle
jdbc.user=myuser
jdbc.password=mypassword
[/sourcecode]
q> Sedangkan untuk file database.properties yang diletakkan pada WAR, example ditaruh di /WEB-INF/database.properties, maka
[sourcecode language="xml"]
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/database.properties" />
</bean>[/sourcecode]
End ::
No comments:
Post a Comment