application.xml配置文件内容截取:
<!-- SqlsessionFactory setup for MyBatis Database Layer -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- mybatis basic config -->
<property name="configLocation" value="classpath:/mybatis-config.xml"/>
<!-- typeAliases -->
<property name="typeAliasesPackage" value="vo,com.feinno.perftrace.web.alarm.vo"/>
<!-- setting the location of mapper -->
<property name="mapperLocations" value="classpath*:mapper/*Mapper.xml"/>
<!-- set "true" in order to catch the errors of declaration of statement more quickly -->
<property name="failFast" value="true"/>
<property name="plugins">
<list>
<!-- use the patch version because of mybatis 3.2's incompatibility-->
<bean class="com.feinno.perftrace.web.dao.ibatis.BindingLogPlugin32"/>
</list>
</property>
</bean>
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory"/>
</bean>
- 配置
sqlSessionFactory
,SqlSessionFactoryBean
是用来产生sqlSessionFactory
的 datasource
参数:加载数据源,使用上面配置好的数据源configLocation
参数: 加载mybatis的全局配置文件mybatis-config.xml(也有叫SqlMapConfig.xml或者mybatis-configuration的,名字任意,在下面指定就好),放在classpath文件夹中typeAliasesPackage
参数:用来设置别名等价于mybatis-configuration.xml中的:
<!-- 别名定义 -->
<typeAliases>
<typeAlias alias="role" type="com.learn.chapter2.po.Role"/>
</typeAliases>
<!-- 如果POJO过多,那么配置起来也是非常麻烦的,MyBatis允许我们通过自动扫描的形式自定义别名(该包下类名首字母小写) -->
<typeAliases>
<package name="cn.wmyskxz.pojo"/>
</typeAliases>
mapperLocations
参数: 用来加载映射文件等价于mybatis-configuration.xml中的:
<configuration>
<mappers>
<!-- 通过 resource 方法一次加载一个映射文件 -->
<mapper resource="sqlmap/UserMapper.xml"/>
<!-- 批量加载mapper -->
<package name="cn.wmyskxz.mapper"/>
</mappers>
</configuration>
评论前必须登录!
注册