美文网首页
Spring配置文件中配置property标签的name和ref

Spring配置文件中配置property标签的name和ref

作者: wyymaomi | 来源:发表于2019-12-27 09:49 被阅读0次

1.ref引用一个已经存在的对象,value创建一个新的对象

2.value可以赋一些简单类型的值,ref可以引用其他的bean对象。

    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="multiDataSource" />
    </bean>

    <!-- 不能用 sqlSessionFactory 作为ID名称-->
    <bean id="sysSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation" value="classpath:mybatis-config.xml" />
        <property name="dataSource" ref="multiDataSource" />
    </bean>

    <bean class="org.springframework.jdbc.core.JdbcTemplate" >
<!--        <property name="dataSource" ref="dataSource"/> -->
        <property name="dataSource" ref="multiDataSource"/>
    </bean>

     <bean id="multiDataSource"
        class="com.jiuhuasoft.smjFrame.multiDataSource.MultiDataSource">
        <property name="defaultTargetDataSource" ref="dataSource"></property>
        <property name="targetDataSources">
            <map>
                <entry key="dataSource1" value-ref="dataSource1"></entry>
            </map>
        </property>
    </bean>

相关文章

网友评论

      本文标题:Spring配置文件中配置property标签的name和ref

      本文链接:https://www.haomeiwen.com/subject/qcbroctx.html