Sometimes, Custom have externalized the location of their property
files to a location outside of the WARs, so their settings are not
wiped out by code updates. The problem is that we have a number of
property files that share the same name.
So that would like to propose that we adopt a unique naming construct for the following files:
* jdbc.properties
* log4j.properties
* hibernate.properties
For each application, we should prefix each of these files with an
identifier that creates a unique name so that the files can be located
in the same directory without overlaying each other. here are my
suggestions for prefixing:
* applicationName-jdbc.properties
* applicationName-log4j.properties
* applicationName-hibernate.properties
Step1:Modfiy Web.xml
Old web.xml
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
New web.xml
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:applicationName-log4j.properties</param-value>
</context-param>
Step2:Modify applicationContext.xml
Old applicationContext.xml
<!-- others -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
p:username="${jdbc.username}" p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<!-- others -->
</list>
</property>
<!-- others -->
New applicationContext.xml
<!-- others -->
<context:property-placeholder location="classpath:applicationName-jdbc.properties"/>
<context:property-placeholder location="classpath:applicationName-hibernate.properties"/>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
p:username="${jdbc.username}" p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<!-- others -->
</list>
</property>
<!-- Add Hibernate property -->
<property name="hibernateProperties">
<value>
hibernate.dialect=${hibernate.dialect}
<!--hibernate.hbm2ddl.auto=${hibernate.dialect} -->
hibernate.cache.provider_class=${hibernate.cache.provider_class}
hibernate.cache.use_query_cache=${hibernate.cache.use_query_cache}
hibernate.generate_statistics=${hibernate.generate_statistics}
hibernate.show_sql=${hibernate.show_sql}
hibernate.cache.use_structured_entries=${hibernate.cache.use_structured_entries}
</value>
</property>
<!-- End Hibernate property -->
</bean>
<!-- others -->
Additional hibernate.properties
## dialect
#hibernate.dialect =org.hibernate.dialect.OracleDialect
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
#hibernate.dialect = org.hibernate.dialect.SQLServerDialect
## cache
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
hibernate.cache.use_query_cache=true
hibernate.cache.use_structured_entries=true
#hibernate.hbm2ddl.auto = update
hibernate.generate_statistics=true
hibernate.show_sql =false
分享到:
评论