1
Ceci est la classe d'aspectdoit définir l'un des « pointcut » ou « pointcut-ref » sur <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");
}
}
Ceci est le fichier de configuration XML avec mon aspect que je l'ai essayé différentes façons, mais toujours son ne fonctionne pas
<?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>
Lorsque je tente de charger ma demande, je reçois cette erreur:
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)
Je vous conseille de quitter la configuration XML pour Spring. Les annotations sont préférées. https://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html – duffymo
La raison pour laquelle j'essaie d'utiliser XML est que mon pointcut ne fonctionnait pas lorsque j'utilisais des annotations –
XML ne va pas le réparer. Le problème est la définition de pointcut. Regardez le lien docs. – duffymo