[spring]xml配置文件中bean属性的两种写法(p:configLocation <=> <property name="configLocation"/>)

1.当作bean节点的属性:p:configLocation:
<!-- mybatis文件配置,扫描所有mapper文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
      p:dataSource-ref="dataSource"
      p:configLocation="classpath:mybatis-config.xml"
      p:mapperLocations="classpath:com/eliteams/quick4j/web/dao/*.xml"/>

2.当作bean节点的属性节点:<property name="configLocation"/>:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource"/>
        <!-- mapper和resultmap配置路径 -->
        <property name="classpath:com/eliteams/quick4j/web/dao/*.xml" />
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>

 注:org.mybatis.spring.SqlSessionFactoryBean:

SqlSessionTemplate中需要的是SqlSessionFactory,而不是SqlSessionFactoryBean。此处使用SqlSessionFactoryBean是因为SqlSessionFactoryBean继承了FactoryBean<SqlSessionFactory>

posted @ 2018-08-14 17:11  vickylinj  阅读(5799)  评论(0编辑  收藏  举报