I am learning about load time weaving possibilities. I know it is possible to inject dependencies in woven beans, but is it possible to inject dependencies on Aspects declared in aop.xml? I am just using the example in the reference manual:
The aspect:
The beans.xmlCode:package foo; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.util.StopWatch; @Aspect public class ProfilingAspect { private StopWatch sw = new StopWatch(getClass().getSimpleName()); private String myName = null; @Around("methodsToBeProfiled()") public Object profile(ProceedingJoinPoint pjp) throws Throwable { try { sw.start(pjp.getSignature().getName()); return pjp.proceed(); } finally { sw.stop(); System.out.println(sw.prettyPrint()); } } @Pointcut("execution(public * foo..*.*(..))") public void methodsToBeProfiled(){} public void setMyName(String myName) { this.myName= myName; } }
The aop.xmlCode:<?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <!-- this switches on the load-time weaving --> <context:load-time-weaver aspectj-weaving="on"/> </beans>
The Main.java file to load the context:Code:<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"> <aspectj> <weaver> <include within="foo.*"/> </weaver> <aspects> <aspect name="foo.ProfilingAspect" /> </aspects> </aspectj>
I'd like to know if there is any way inject dependencies in the profilinig aspect. I see no obvious way as the aspect is not in spring-config.xmlCode:package foo; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public final class Main { public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext("/beans.xml", Main.class); EntitlementCalculationService entitlementCalculationService = new StubEntitlementCalculationService(); entitlementCalculationService.calculateEntitlement(); } }


Reply With Quote
