Springプロファイルにpropertiesファイルを使う
2161 ワード
Springを使用して提供されたorg.spring frame ewark.beans.factory.co.fig.ProptyPlace holderConfigrerはpropertiesファイルを導入し、appectionContextファイルの他の部分で$を参照します.
以上はspringside.com.cnを参照してください.
"propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
lazy-init="false">
"locations">
classpath*:dao.properties
org.sprigframe ewark.beans.factory.co.nfig.PropertyOverrideConfigrerを使用すると、propertiesファイルの値で、appliation Contectで定義されているbeanのproperty値をカバーすることができます.例えば、// bean , ${jdbc.url} dao.properties
"dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
"jdbcUrl">
${jdbc.url}
// PropertyOverrideConfigurer, properties test.properties
"testPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
"location" value="classpath:context/test/test.properties"/>
"ignoreInvalidKeys" value="true"/>
//test.properties dataSource jdbcUrl :
dataSource.jdbcUrl=jdbc:hsqldb:res:db
testPropertyConfigrerを単独のxmlファイルに入れます.このxmlをロードしないなら、data Source.jdbcUrlはdao.propertiesの値です.このファイルを読み込むと、dataSource.jdbcUrlはtest.propertiesの値です.以上はspringside.com.cnを参照してください.