spring 中的配置文件的好习惯

来源:互联网 发布:恒大品牌部网络监控员 编辑:程序博客网 时间:2024/06/05 04:26
spring 中的配置文件的好习惯,其中一个我觉得是象SPRING里配置数据驱动等,可以先用一个比如init.properties的文件写下关键部分,比如

datasource.driverClassName=org.gjt.mm.mysql.Driver
。。。。。。。

hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.jdbc.batch_size=25
hibernate.jdbc.fetch_size=50
hibernate.show_sql=true
hibernate.hbm2ddl.auto=none
然后在比如applicationcontext.xml中,可以这样写

<beans>
 <bean id="placeholderConfig"
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
   <list>
    <value>WEB-INF/init.properties</value>
   </list>
  </property>
 </bean>

 <bean id="dataSource"
  class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName">
   <value>${datasource.driverClassName}</value>
  </property>
  <property name="url">
   <value>${datasource.url}</value>
  </property>

,。。。。。
</bean>

原创粉丝点击