Spring Dependency Внедрение аннотированного аспекта
Использование Spring У меня были некоторые проблемы с внедрением зависимостей в аннотированный класс Aspect. CacheService внедряется при запуске контекста Spring, но когда происходит переплетение, он говорит, что cacheService имеет значение null. Поэтому я вынужден вручную просмотреть контекст весны и получить бин оттуда. Есть ли другой способ сделать это?
Вот пример моего Аспекта:
import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import com.mzgubin.application.cache.CacheService;
@Aspect
public class CachingAdvice {
private static Logger log = Logger.getLogger(CachingAdvice.class);
private CacheService cacheService;
@Around("execution(public *com.mzgubin.application.callMethod(..)) &&"
+ "args(params)")
public Object addCachingToCreateXMLFromSite(ProceedingJoinPoint pjp, InterestingParams params) throws Throwable {
log.debug("Weaving a method call to see if we should return something from the cache or create it from scratch by letting control flow move on");
Object result = null;
if (getCacheService().objectExists(params))}{
result = getCacheService().getObject(params);
} else {
result = pjp.proceed(pjp.getArgs());
getCacheService().storeObject(params, result);
}
return result;
}
public CacheService getCacheService(){
return cacheService;
}
public void setCacheService(CacheService cacheService){
this.cacheService = cacheService;
}
}