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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- DAO层配置 -->
<!-- 加载外部数据库属性文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"></property>
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!-- 配置SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- 引入sqlMapConfig.xml文件 -->
<property name="configLocation" value="classpath:sqlMapConfig.xml"></property>
<!-- 配置别名 -->
<property name="typeAliasesPackage" value="cn.hp.entity"></property>
</bean>
<!-- 扫描DAO层接口的包,创建动态代理对象,存入到spring容器中 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="cn.hp.dao"></property>
</bean>
<!-- 业务层 -->
<!-- 开启注解 -->
<context:component-scan base-package="cn.hp.service"/>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 注入数据源 -->
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 开启事务注解 -->
<tx:annotation-driven/>
<!-- 日志 -->
<!--<bean id="logController" class="cn.hp.log.LogController"></bean>
<aop:config>
<aop:pointcut expression="execution(* cn.hp.controller.*.*(..))" id="pc"/>
<aop:aspect ref="logController">
<aop:around method="around" pointcut-ref="pc"/>
</aop:aspect>
</aop:config>-->
</beans>
jdbc.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mydb
jdbc.username=root
jdbc.password=123456
spring-mvc.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<!-- 扫描控制器 -->
<context:component-scan base-package="cn.hp.controller"/>
<!-- 注解驱动:处理器适配器和处理器映射器 -->
<mvc:annotation-driven conversion-service="conversionService"/>
<!-- 视图解析器 -->
<!-- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">-->
<!-- <property name="prefix" value="/pages/"></property>-->
<!-- <property name="suffix" value=".jsp"></property>-->
<!-- </bean>-->
<!-- 文件上传 -->
<!-- 拦截器 -->
<!-- 自定义类型转换器 -->
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="cn.hp.converter.StringToDateConverter"></bean>
</set>
</property>
</bean>
<!-- 静态资源全部放行 -->
<mvc:default-servlet-handler/>
<!-- aop的自动代理 -->
<!--<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>-->
<!--配置开启security的注解支持-->
<!--<security:global-method-security secured-annotations="enabled"/>-->
</beans>
sqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/myb