Outils pour utilisateurs

Outils du site


lang:java:spring

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
lang:java:spring [2016/12/17 23:22] – Création rootlang:java:spring [2020/05/11 00:07] (Version actuelle) – Suppression de la taille par défaut pour les images root
Ligne 4: Ligne 4:
  
 =====Cycle de vie d'un Bean===== =====Cycle de vie d'un Bean=====
-{{:lang:java:spring:spring-bean-life-cycle.png?524|Cycle de vie d'un Bean Spring}} +{{:lang:java:spring:spring-bean-life-cycle.png|Cycle de vie d'un Bean Spring}}
- +
-[[http://howtodoinjava.com/spring/spring-core/spring-bean-life-cycle/|Source]], {{ :lang:java:spring:spring_bean_life_cycle_tutorial_-_howtodoinjava.htm.maff |Archive}}+
  
 +[[https://howtodoinjava.com/spring/spring-core/spring-bean-life-cycle/|Spring Bean Life Cycle Tutorial - HowToDoInJava]] {{ :lang:java:spring:spring_-_bean_life_cycle_explained_-_howtodoinjava_2019-12-13_22_09_42_.html |Archive du 05/2013 le 13/12/2019}}
 =====POA autour d'un bean managé===== =====POA autour d'un bean managé=====
 Bean basique Bean basique
Ligne 97: Ligne 96:
   INFOS: Closing org.springframework.context.support.ClassPathXmlApplicationContext@1f17ae12: startup date [Sat Dec 17 23:45:11 CET 2016]; root of context hierarchy   INFOS: Closing org.springframework.context.support.ClassPathXmlApplicationContext@1f17ae12: startup date [Sat Dec 17 23:45:11 CET 2016]; root of context hierarchy
  
 +=====En combinaison avec AspectJ=====
 +<WRAP center round important 60%>
 +Le projet ne doit pas être configuré en AspectJ mais les libraires d'AspectJ doivent être dans le ''Build path''.
 +</WRAP>
 +
 +On travaille avec la même classe ''Bonjour'' (package ''fonction'') que ci-dessus.
 +
 +<file java Logging.java>
 +package aspects;
 +
 +import org.aspectj.lang.annotation.Around;
 +import org.aspectj.lang.annotation.Aspect;
 +
 +@Aspect
 +public class Logging {
 +  @Around("execution(* fonction.Bonjour.getMessage())")
 +  public String aroundGetMessage()
 +  {
 +    return "INTERCEPTION";
 +  }
 +}
 +</file>
 +
 +<file java Main.java>
 +package test;
 +
 +import org.springframework.context.ConfigurableApplicationContext;
 +import org.springframework.context.support.ClassPathXmlApplicationContext;
 +
 +import fonction.Bonjour;
 +
 +public class Main {
 +  public static void main(String[] args) {
 +    try (ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("Beans.xml")) {
 +      Bonjour bonjour = (Bonjour) ctx.getBean("bonjour");
 +
 +      System.out.println(" Compte : " + bonjour.getMessage());
 +    }
 +  }
 +}
 +</file>
 +
 +Le fichier ''Beans.xml'' est dans le dossier ''src''.
 +
 +Ici, il faut charger la classe bean ''fonction.Bonjour'' et la classe contenant l'aspect ''aspects.Logging''.
 +
 +''aspectj-autoproxy'' indique qu'on travaille avec ''AspectJ'' et pas avec ''Spring AOP''.
 +<file xml Beans.xml>
 +<?xml version="1.0" encoding="UTF-8"?>
 +<beans:beans xmlns:aop="http://www.springframework.org/schema/aop"
 +  xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 +  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd ">
 +  <aop:aspectj-autoproxy />
 +  <beans:bean id="bonjour" class="fonction.Bonjour" />
 +  <beans:bean class="aspects.Logging" />
 +</beans:beans>
 +</file>
lang/java/spring.1482013360.txt.gz · Dernière modification : 2016/12/17 23:22 de root