PropertyPlaceholderConfigurer配置

1,在配置文件中使用占位符“$”,可以使用PropertyPlaceholderConfigurer,
如: <bean id="config" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath*:config-hibernate.properties</value>
    </list>
    </property>
    </bean>
在src下有一个配置文件:config-hibernate.properties。内容:
jndiName=datasource
resourceRef=true
java.naming.provider.url=t3\://localhost\:7001
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
hibernate.dialect=org.hibernate.dialect.OracleDialect
hibernate.query.substitutions=true 'T', false 'F'
hibernate.show_sql=true


2,然后就可以在配置文件中通过占位符来利用了
如: <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">   
  <property name="jndiName"> 
     <value>${jndiName}</value>
  </property>   
  <property name="resourceRef"> 
     <value>${resourceRef}</value>
  </property> 
  <property name="jndiEnvironment"> 
     <props> 
     <prop key="java.naming.provider.url">${java.naming.provider.url}</prop> 
     <prop key="java.naming.factory.initial">${java.naming.factory.initial}</prop> 
     </props> 
  </property>   
 </bean> 


    
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                   ${hibernate.dialect}
                </prop>
                <prop key="hibernate.query.substitutions">
                    ${hibernate.query.substitutions}
                </prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                <value>com/entity/Demo.hbm.xml</value>
            </list>
        </property>
    </bean> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值