我配置为啥没有增强啊,是哪里错误了 麻烦老师看看
package com.imooc.Demo5;
public class Studao {
public void add() {
System.out.println("添加");
}
public void delect() {
System.out.println("删除");
}
public void update() {
System.out.println("修改");
}
public void sava() {
System.out.println("查询");
}
}package com.imooc.Demo5;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class MyAroundAdvice implements MethodInterceptor {
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
//在这前就是环绕前通知
// 执行目标方法
System.out.println("环绕前增强");
Object proceed = methodInvocation.proceed();
//环绕后通知
System.out.println("环绕后增强");
return proceed;
}
}Springaop 配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 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"> <!--配置目标类--> <bean id="Studao" class="com.imooc.Demo5.Studao"></bean> <!--环绕通知配置--> <bean id="myAroundAdvice" class="com.imooc.Demo5.MyAroundAdvice"></bean> <!--一般切面是用通知为切面,带切入点的要先配置待遇切入点的切面--> <bean id="myadvice" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <!--配置切入点 正则表达式--> <property name="pattern" value=".*save.*"/> <!--使用哪种配置通知--> <property name="advice" ref="myAroundAdvice"/> </bean> <bean id="test2" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="target" ref="Studao"/> <property name="proxyTargetClass" value="true"/> <property name="interceptorNames" value="myadvice"/> </bean> </beans>
测试类
package com.imooc.Demo5;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:Springaop2.xml")
public class test {
@Resource(name = "test2")
private Studao studao;
@Test
public void test(){
studao.add();
studao.delect();
studao.update();
studao.sava();
}
}0
收起
正在回答 回答被采纳积分+1
5回答
AlanLiu0328
2018-11-11 20:29:12
兄弟, 你在XML里是save。 实际代码是sava。 当然不行。 另外delect是什么鬼?
SSM主流框架入门与综合项目实战2018版
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星