Hi
I would like to tap into the full power of AspectJ in Spring therefore I want to create an aspect and use it in my application.xml file of spring. However when I create a bean in the application.xml and actually do logic, no entering method: text occurs on console....
However if I convert my java project to adjt project and compile i get the text...entering method etc... because the aspect is woven into code at compile time...
What I am trying to do is get spring to weave in the AspectJ aspect - not Spring AOP(retrieved using aspectOf in factory-method) into my code at runtime/loadtime when code is running...
I would like to be able to dynamically remove the aspectJ aspect from xml and have spring act appropriately..
Code:// // This aspect allows us to perform logging using Log4j. // // Change History; // 17th Aug 11 (v1.0) - Updated comments to work with javadoc. // package nz.ac.vuw.oim.utils.logging; // Include required libraries import org.apache.log4j.Logger; import org.aspectj.weaver.Aspect; public aspect LoggingAspect { // Setup variables private Logger m_objLogger = Logger.getLogger(LoggingAspect.class); private Boolean m_bolLogAllMethods = false; // Where do we want to log pointcut logAllMethods() : execution(* *(..)); // Log every method call //pointcut logMe() : execution(* set*(..)); // Log every method call /**************************************************************************************************** * Create a logging aspect that will use Log4J. ***************************************************************************************************/ public LoggingAspect() {} /**************************************************************************************************** * Shall we log all methods? ***************************************************************************************************/ public void setLogAllMethods(boolean bolLogAllMethods) { m_bolLogAllMethods = bolLogAllMethods; } /**************************************************************************************************** * Create a logging aspect that will use Log4J. ***************************************************************************************************/ Object around() : logAllMethods() { //m_objLogger.debug("Entering method: " ); System.out.println("Entering method: " + thisJoinPoint.getSignature().getName()); return proceed(); //m_objLogger. } }Code:<?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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- ASPECTJ LOGGING --> <bean id="loggingAspect" class="nz.ac.vuw.oim.utils.logging.LoggingAspect" /> </beans>


Reply With Quote