【发布时间】:2017-06-21 20:39:16
【问题描述】:
这是方面类
public class TransactionAspect {
public void beforeAnything() throws IOException{
System.out.println("In the aspect");
}
public void beforeWithdrawalTransaction() throws IOException{
System.out.println("In the aspect");
}
public void beforeDepositTransaction() throws IOException{
System.out.println("In the aspect");
}
public void beforeBalance() throws IOException{
System.out.println("In the aspect");
}
}
这是我方面的 xml 配置文件,我尝试了不同的方法,但仍然无法正常工作
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<aop:config>
<aop:pointcut id="forAnything" expression="execution(* com.pack.service.*.*(..))" />
<aop:advisor advice-ref="myAspectBean" pointcut="forAnything" id="interceptor" ></aop:advisor>
<aop:aspect id="myAspect" ref="myAspectBean">
<aop:before method="beforeWithdrawalTransaction" />
<aop:before method="beforeDepositTransaction" />
<aop:before method="beforeBalance"/>
</aop:aspect>
</aop:config>
<bean id="myAspectBean" class="com.pack.aspect.TransactionAspect"/>
</beans>
当我尝试加载我的应用程序时,我收到此错误:
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Must define one of 'pointcut' or 'pointcut-ref' on <advisor> tag.
Offending resource: class path resource [Spring.xml]
Aspect: id='myAspect'
-> Advice (before)
【问题讨论】:
-
我建议您不要使用 Spring 的 XML 配置。注释是首选。 docs.spring.io/spring/docs/current/spring-framework-reference/…
-
我尝试使用 XML 的原因是因为当我使用注释时我的切入点不起作用
-
XML 不会修复它。问题是切入点定义。查看文档链接。
标签: java xml spring aop spring-aop