(1)导包
(2)目录结构
(3)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: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/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 配置c3p0连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 注入属性值 -->
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/test"></property>
<property name="user" value="root"></property>
<property name="password" value="admin"></property>
</bean>
<bean id="userService" class="cn.yyf.c3p0.UserService">
<!-- 注入dao对象 -->
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="userDao" class="cn.yyf.c3p0.UserDao">
<!-- 注入jdbcTemplate对象 -->
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>
<!-- 创建jdbcTemplate对象 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<!-- 把dataSource传递到模板对象里面 -->
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 开启 aop 注解的自动代理: -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<!-- 1 配置对象 -->
<bean id="book" class="cn.yyf.aop.Book"></bean>
<bean id="myBook" class="cn.yyf.aop.MyBook"></bean>
</beans>
(4)UserDao.java
(5)UserService.java
测试类