Bonjour,
j'essaie d'intégrer Spring dans une appli Web et plus particulièrement Spring AOP.

J'ai spécifié mon aspect-config.xml pour ajouter un aspect :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xmlns:aop="http://www.springframework.org/schema/aop"
		xsi:schemaLocation="http://www.springframework.org/schema/beans
							http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
							http://www.springframework.org/schema/aop
							http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
 
	<bean id="loggerException" class="loc.sppgroup.production.sampy.aspects.ExceptionLogger">
	</bean>
 
	<aop:aspectj-autoproxy>
		<aop:include name="loggerException"/>
	</aop:aspectj-autoproxy>
 
</beans>
J'ai ajouté mon aspect :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package loc.sppgroup.production.sampy.aspects;
 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
 
@Aspect
public class ExceptionLogger 
{
	private static Log log = null;
 
	static
	{
		log = LogFactory.getLog(ExceptionLogger.class);
	}
 
	public ExceptionLogger ()
	{
		int a =0;
		a++;
	}
 
	@AfterThrowing(
		pointcut="* loc..*.*(..)",
		throwing="ex")
	public void dologgingActions(JoinPoint joinPoint, Throwable ex) 
	{
		if (joinPoint != null && ex != null)
		{
			log.error(joinPoint.getSignature().toLongString());
			log.error(ex);
		}
	}
 
	@Before ("* loc..*.*(..)")
	public void doBefore ()
	{
		int a=0;
                a++;
	}
 
	@Around("execution(* loc..*.*(..))")
	public Object encoreuntest(ProceedingJoinPoint method) throws Throwable {
		int a = 0;
		return method.proceed();
	}
}
Je constate que je ne passe JAMAIS par aucun de mes greffons.
J'ai pourtant mis un point d'arrêt sur le constructeur et le static log de mon aspect et j'y passe bien. Par contre, pour les @Before, @AfterThrowing et @Around, rien du tout. J'ai pourtant spécifié large en indiquant que je voulais passer par toutes les méthodes des classes de tous les package de mon application.

J'ai bien spécifié mon fichier de configuration aspect dans mon web.xml :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
	<!-- Spring Application Context -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/application-config.xml /WEB-INF/aspects-config.xml</param-value>
	</context-param>
 
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
Et lorsque je démarre mon serveur, j'ai bien la prise en compte de Spring AOP :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
INFO [org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization started
INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Refreshing Root WebApplicationContext: startup date [Wed Feb 01 10:46:06 CET 2012]; root of context hierarchy
INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from ServletContext resource [/WEB-INF/application-config.xml]
INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from ServletContext resource [/WEB-INF/aspects-config.xml]
INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1a1ad24: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,loggerException,org.springframework.aop.config.internalAutoProxyCreator]; root of factory hierarchy
INFO [org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization completed in 1421 ms
Ma question est : pourquoi est-ce que je ne passe jamais par mes aspects ?
Merci


PS : je tiens à préciser que j'ai ajouté les librairies aspectjrt et aspectjweaver dans mon projet pour l'utilisation des annotations aspectj