目录
1、项目配置
1.1 创建Java项目
1.2 加Spring依赖包和配置文件
1)添加相关jar包;
2)添加spring配置文件applicationContext.xml到resources/spring资源配置目录下。
3)添加日志记录工具log4j及数据源属性文件等相应配置文件。
注意:因为这里没有整合web内容,所以没有web.xml文件,也就不需要在其中添加spring 的监听器。
1.3 加MyBatis依赖包和配置文件
- 添加相关jar包,尤其不要忘记加载mybatis-spring的jar包;
- 添加mybatis配置文件mybatis-config.xml到resources/mybatis资源配置目录下。
2、MyBatis和Spring整合
2.1 配置spring数据源
在applicationContext.xml文件中添加如下内容:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <!-- 允许JVM参数覆盖 --> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <!-- 忽略没有找到的资源文件 --> <property name="ignoreResourceNotFound" value="true" /> <!-- 配置资源文件 --> <property name="locations"> |