日期:2014-05-18  浏览次数:20558 次

关于Spring配置文件有一处不太懂,求教...

     <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:properties/dataBase.properties</value>
        </property>
    </bean> 
 
    <bean id="dataSource"  class="org.apache.commons.dbcp.BasicDataSource">
        <property name="url">
            <value>${database.url}</value>
        </property>   
        <property name="driverClassName">
            <value>${database.driver}</value>
        </property>
        <property name="username">
            <value>${database.user}</value>
        </property>
        <property name="password">
            <value>${database.password}</value>
        </property>
    </bean> 

这里的${...}是什么意思?
------解决方案--------------------
引用:
Quote: 引用:

spring的el表达式,这里就是取里配置文件里面的database.xxxx的值

那database从哪里出来的呢?

你spring的xml里面的<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:properties/dataBase.properties</value>
        </property>
    </bean> 
这里就已经把dataBase.properties配置文件交给spring管理了,${database.xxxxx}这些就是从这里面取到的,更多的看人家spring的开发文档