这是applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd "
>
<!-- ............................................华丽的分割线................................................ -->
<!-- Spring希望管理所有的业务逻辑组件,等等.....
另外,如果有下面这条配置用来扫描包路径选项,则不再需要撰写这条<context:annotation-config />来提供注解支持了
另外另外,请注意!!!尽量不要用方法3,此为错误方法,会出现各种让你欲哭无泪的404、500等错误提示
-->
<!-- 方法1(笨方法):
<context:component-scan base-package="com.sundi.hrm.dao" />
<context:component-scan base-package="com.sundi.hrm.pojo" />
<context:component-scan base-package="com.sundi.hrm.service" />
-->
<!-- 方法2(简便方法): -->
<context:component-scan base-package="com.sundi.hrm">
<!-- 不希望用spring管理springMVC的内容,把Controller剔除掉 -->
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 方法3:(错误方法) 搞成下面这种会出现500错误 ,不知道为何!
<context:component-scan base-package="dao,pojo,service" />
-->
<!-- ............................................华丽的分割线............................................... -->
<!-- ............................................华丽的分割线............................................... -->
<!-- 引入数据库的配置文件 -->
<context:property-placeholder location="classpath:db.properties" />
<!-- Spring用来控制业务逻辑。数据源、事务控制、aop -->
<!-- 使用数据源c3p0 类型 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- spring事务管理 -->
<bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 开启基于注解的事务 -->
<tx:annotation-driven transaction-manager="dataSourceTransactionManager"/>
<!-- ............................................华丽的分割线............................................... -->
<!-- ............................................华丽的分割线............................................... -->
<!-- 整合mybatis !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
目的:1、spring管理所有组件 mapper的实现类。
service==>Dao @Autowired:自动注入mapper;
2、spring用来管理事务,spring声明式事务
-->
<!--创建出SqlSessionFactory对象 -->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- configLocation指定全局配置文件的位置 -->
<property name="configLocation" value="classpath:mybatis-config.xml" />
<!--mapperLocations: 指定mapper文件的位置-->
<property name="mapperLocations" value="classpath:mybatis/mapper/*.xml" />
<!-- 扫描POJO包 自动提供别名,以后POJO里面的类就不用写全类名了 -->
<property name="typeAliasesPackage" value="com.sundi.hrm.pojo" />
</bean>
<!-- 扫描所有的mapper接口的实现,让这些mapper能够自动注入;base-package:指定mapper接口的包名-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.sundi.hrm.dao"></property>
</bean>
<!--此条和上面这个功能一样 <mybatis-spring:scan base-package="com.atguigu.mybatis.dao"/> -->
<!-- ............................................华丽的分割线............................................... -->
</beans>