SSM项目要想成功运转,少不了几个关键文件的正确配置的支撑,如applicationContext.xml、springmvc-servlet.xml、mybatis-config.xml、ehcache.xml、dbconfig.properties等。本文介绍第一个:applicationContext.xm。
applicationContext.xml主要用于整合Spring和MyBatis两大框架,实现读取服务器数据和将业务逻辑处理的数据进行持久化操作。需要配置的主要节点有:
1、<context:annotation-config />用于启用注解;
2、<context:component-scan base-package="com.krk.pc600">用于设置默认扫描包,
3、<bean id="dataSource" class="" destroy-method="close"> 用于配置数据源、数据库基本信息。其中配置destroy-method="close"作用是当数据库连接不用时,就把连接放在连接边,方便下次调用。
4、<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">用于 配置扫描器 ,扫描所有映射接口类。
5、<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 用于配置事务管理器
6、<aop:config>用于配置事务切点, 并把切点和事务属性关联起来
7、<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">用于spring和MyBatis整合。
以上是我的简单见解,后续继续完善,由于时间的关系,恐有不妥之处,欢迎指正。