String et utilisation @Aspect
Bonjour,
je souhaite rajouter la notion d'aspect dans mon application. Cependant j'ai déjà un petit problème. En effet, mes aspects ne sont pas pris en compte.
Voilà le code :
context.xml
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
|
<?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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!-- CONFIGURATION DES ASPECTJ -->
<aop:aspectj-autoproxy proxy-target-class="true" />
<bean id="tracerAdvice" class="com.application.aspect.SysoutInterceptor" />
<!-- CONFIGURATION DE LA PARTIE CONTEXT -->
<context:annotation-config />
<context:component-scan base-package="com.application.service" />
<!-- CONFIGURATION DE LA PARTIE UTIL -->
<util:list id="liste" list-class="java.util.ArrayList" scope="prototype"/>
<util:map id="map" map-class="java.util.HashMap" scope="prototype" />
<util:set id="set" set-class="java.util.HashSet" scope="prototype" />
</beans> |
Class main
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
package com.application.main;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.application.service.IUtilisateurService;
public class Launcher {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
IUtilisateurService service = (IUtilisateurService)context.getBean("utilisateurService");
System.out.println(service.validate(null));
}
} |
Les interfaces
Code:
1 2 3 4 5 6 7 8 9 10
|
package com.application.service;
import com.application.om.Adresse;
public interface IAdresseService {
boolean validate(Adresse adresse);
} |
Code:
1 2 3 4 5 6 7 8 9 10
|
package com.application.service;
import com.application.om.Utilisateur;
public interface IUtilisateurService {
boolean validate(Utilisateur utilisateur);
} |
Une des implémentations :
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
|
package com.application.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.application.om.Utilisateur;
import com.application.service.IAdresseService;
import com.application.service.IUtilisateurService;
@Service
public class UtilisateurService implements IUtilisateurService {
public IAdresseService getAdresseService() {
return adresseService;
}
@Autowired
public void setAdresseService(IAdresseService adresseService) {
this.adresseService = adresseService;
}
private IAdresseService adresseService ;
@Override
public boolean validate(Utilisateur utilisateur) {
if(utilisateur == null)
return false;
if(utilisateur.getNom() == null || utilisateur.getNom().equals(""))
return false ;
if(utilisateur.getPrenom() == null || utilisateur.getPrenom().equals(""))
return false ;
return adresseService.validate(utilisateur.getAdresse());
}
} |