I have the following class:
With the following Spring xml:Code:public class SomeClass { public void doSomething() { logThisMessage("SomeClass wants to log"); } public void logThisMessage(String inputStr) {} }
My Aspect is the following: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:tx="http://www.springframework.org/schema/tx" 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/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd "> <bean id="someClassBean" class="com.loggingserviceframework.app.SomeClass"/> <bean id="loggingAspect" class="com.loggingserviceframework.aop.LoggingAspect"/> <aop:config> <aop:aspect ref="loggingAspect"> <aop:pointcut id="myCutLogging" expression="execution(* logThisMessage(..))"/> <aop:around pointcut-ref="myCutLogging" method="log"/> </aop:aspect> </aop:config> </beans>
My question is, how do I monitor the logThisMessage call? My goal is to set up an aspect that monitors every time a logThisMessage is called from all my classes which could be hundreds. I'm am very new to Spring AOP or AOP in general, so not even sure if this can be done.Code:public class LoggingAspect { public void log(ProceedingJoinPoint call) throws Throwable { System.out.println("Entering Aspect..."); System.out.println(call.getArgs()[0]); } }
The implementing class is:
Code:public class AppLauncher { /** * @param args */ public static void main(String[] args) { ApplicationContext appContext = new ClassPathXmlApplicationContext( new String[] { "dosomethingtest.xml" }); SomeClass someClass = (SomeClass) appContext.getBean("someClassBean"); someClass.doSomething("SomeClass wants to log"); } }


Reply With Quote