Problème ajout de code avec AOP. Chargement de bean incorrect?
Bonjour,
Je cherche a créer un intercepteur avec aop et pour cela j'ai suivi le super tutorial suivant
Mais cela ne marche pas du tout mais je n'ai pas de message d'erreur ni de problème de compilation, et mon programme est bien chargé en mémoire! Et du coup je voit pas du tout d'où l'erreur peut venir!
Voici ce que j'ai modifier :
Dans le fichier spring.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <!-- Début de la configuration AOP -->
<bean id="LoggerIntercepteurImpl" class="com.renaultvi.k06dmsirc.util.tools.intercepteur.LoggerIntercepteurImpl" /> <!-- lazy-init="true" /> -->
<aop:config>
<aop:pointcut id="servicePointcut" expression="execution(* com.xxx.xxx.*.*(..))"/>
<aop:aspect id="loggingAspect" ref="LoggerIntercepteurImpl">
<aop:before method="logMethodEntry" pointcut-ref="servicePointcut"/>
<aop:after-returning method="logMethodExit" returning="result" pointcut-ref="servicePointcut"/>
</aop:aspect>
</aop:config>
<!-- Fin de la configuration AOP --> |
et dans le fichier de conf de log4J.xml
Code:
1 2 3 4 5 6 7 8 9 10 11
| <appender name="fichier" class="org.apache.log4j.FileAppender">
<param name="File" value="./LogGood.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="IRC - %m%n - %d %-5p %C{2} - %t - %F:%L - %m%n " />
</layout>
</appender>
<root>
<level value="INFO"/>
<appender-ref ref="fichier"/>
</root> |
et voici le code de la classe de l'intercepteur :
Code:
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
|
public class LoggerIntercepteurImpl implements LoggerIntercepteur
{
private long m_duree = 0;
private Log LOGGERIntercepteur;
public LoggerIntercepteurImpl()
{
System.out.println("Byzarre");
}
public void logMethodEntry(JoinPoint joinPoint)
{
Log LOGGERIntercepteur = LogFactory.getLog(joinPoint.getThis().getClass());
m_duree = System.currentTimeMillis();
Object[] args = joinPoint.getArgs();
// Nom de la méthode interceptée
String name = joinPoint.getSignature().toLongString();
StringBuffer sb = new StringBuffer(name + " called with: [");
// Liste des valeurs des arguments reçus par la méthode
for (int i = 0; i < args.length; i++)
{
Object o = args[i];
sb.append("'" + o + "'");
sb.append((i == args.length - 1) ? "" : ", ");
}
sb.append("]");
LOGGERIntercepteur.fatal("intercepteur : " + sb);
System.out.println("intercepteur : " + sb);
}
public void logMethodExit(StaticPart staticPart, Object result)
{
// Nom de la méthode interceptée
String name = staticPart.getSignature().toLongString();
LOGGERIntercepteur.info(name + " and returning: [" + result + "] en " + (System.currentTimeMillis() - m_duree) + " ms");
System.out.println(name + " and returning: [" + result + "] en " + (System.currentTimeMillis() - m_duree) + " ms");
} |
Je sais que c'est byzarre :D de mettre un truc dans le constructeur d'un intercepteur mais c'est le seul signe de vie que j'ai pu avoir de cette classe (ce sysout fonctionne) ! Alors que normalement je devrais avoir quelques centaines de ligne au démarrage de mon application!
Sinon j'ai ce log la, cela a peut être quelque chose a voir avec mon histoire? Parce que j'ai l'impression que mon intercepteur est compris comme une classe "normal" :
INFO support.DefaultListableBeanFactory - main - DefaultListableBeanFactory.java:414 - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@dfe303: defining beans [
"""la liste de mes beans présent dans le fichier spring.xml et qui se finissent par les éléments suivants :: """
LoggerIntercepteurImpl,org.springframework.aop.config.internalAutoProxyCreator,servicePointcut,org.springframework.aop.aspectj.AspectJPointcutAdvisor#0,org.springframework.aop.aspectj.AspectJPointcutAdvisor#1]; root of factory hierarchy