发表于: 2017-04-18 22:09:34
2 1362
今天完成的事情:
1.学习 AOP 切面
2.初看事务管理
明天计划的事情:
1.学习 AOP 切面
2.学习简单的 JDBCTemplate
3.学习 AOP 事务管理
遇到的问题:
1.为什么我的 @Around 环绕增强不起作用
<bean id="userManager" class="com.draper.UserManagerImpl"/>
<bean id="securityHandler" class="com.draper.SecurityHandler"/>
<aop:config proxy-target-class="true">
<aop:aspect id="securityHandlerAspect" ref="securityHandler">
<aop:pointcut id="add" expression="execution(* add*(..))"/>
<aop:around method="checkSecurity" pointcut-ref="add"/>
</aop:aspect>
</aop:config>
public class SecurityHandler {
private void checkSecurity() {
System.out.println("--------checkSecurity()--------");
}
}
public class UserManagerImpl implements UserManager {
public void addUser(String userName, String password) {
System.out.println("添加用户" + userName + "\t" + "密码" + password);
}
}
public class Client {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("Application-Context.xml");
UserManager userManager = (UserManager)context.getBean("userManager");
userManager.addUser("张三", "123");
}
}
讲道理来说环绕增强应该输出
--------checkSecurity()--------
添加用户张三 密码123
--------checkSecurity()--------
但实际上是
不论是采用注解配置的方式还是Spring 配置文件的配置的方式都是如此,请师兄解惑
评论