目录
1.2 第二步:在配置文件中导入 context 的名称空间
2.2 第二步:在通知类上使用@Aspect 注解声明为切面
2.4 第四步:在 spring 配置文件中开启 spring 对注解 AOP 的支持
-
1 环境搭建
-
1.1 第一步:准备必要的代码和 jar 包
- 拷贝上一小节的工程即可。
-
1.2 第二步:在配置文件中导入 context 的名称空间
-
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.xsd"> <!-- 配置数据库操作对象 --> <bean id="dbAssit" class="com.itheima.dbassit.DBAssit"> <property name="dataSource" ref="dataSource"></property> <!-- 指定 connection 和线程绑定 --> <property name="useCurrentConnection" value="true"></property> </bean> <!-- 配置数据源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="com.mysql.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql:///spring_day02"></property> <property name="user" value="root"></property> <property name="password" value="1234"></property> </bean> </beans>
-
-
1.3 第三步:把资源使用注解配置
- 账户的业务层实现类
-
@Service("accountService") public class AccountServiceImpl implements IAccountService { @Autowired private IAccountDao accountDao; }
- 账户的持久层实现类
-
@Repository("accountDao") public class AccountDaoImpl implements IAccountDao { @Autowired p
-