1
之一這方面類必須定義「切入點」或「切入點-REF」上<advisor>
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配置。註釋是首選。 https://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html – duffymo
我試圖使用XML的原因是因爲當我使用註釋時,我的切入點不起作用 –
XML不會解決它。問題在於切入點的定義。看看文檔鏈接。 – duffymo