Como já postei em outros tópicos, estou criando um Gestor de Cache.
Eu tentei n possibilidades para implementar o aspecto.
Primeira implementação do aspecto:
AutoCacheAspect
package cc.marcio.systems.aspects;
@Aspect
public class AutoCacheAspect {
private ICacheManager cacheManager;
@Around( "@annotation(cc.marcio.systems.annotations.AutoCache)" )
public Object intercept(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("Tentando injeção em um aspecto -> "+ cacheManager.test());
return pjp.proceed();
}
public void setCacheManager(ICacheManager cacheManager) {
System.out.println("Setando o cachemanager");
this.cacheManager = cacheManager;
}
}
Segunda implementação do aspecto:
AutoCacheAspect
package cc.marcio.systems.aspects;
public aspect AutoCacheAspect {
private ICacheManager cacheManager;
Object around() : @annotation( cc.marcio.systems.annotations.AutoCache ) {
System.out.println("Tentando injeção em um aspecto -> "+ cacheManager.test());
return proceed();
}
public void setCacheManager(ICacheManager cacheManager) {
System.out.println("Setando o cachemanager");
this.cacheManager = cacheManager;
}
}
ApplicationContext.xml
<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" xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd">
<bean id="pessoaDao" class="cc.marcio.systems.cache.dao.impl.PessoaDaoImpl" />
<bean id="pessoaService" class="cc.marcio.systems.cache.service.impl.PessoaServiceImpl">
<property name="pessoaDao" ref="pessoaDao" />
</bean>
<aop:aspectj-autoproxy />
<bean id="cacheManager" class="cc.marcio.systems.cache.impl.TestCacheManagerImpl" />
<bean id="autoCacheAspect" class="cc.marcio.systems.aspects.AutoCacheAspect">
<property name="cacheManager" ref="cacheManager" />
</bean>
</beans>
Em ambas as implementações, o aspecto funciona perfeitamente. O único detalhe é que esta gerando um nullpointerexception qdo tenta executar um método do cacheManager, que foi injetado pelo Spring. Eu coloquei um print no set do objeto para ver se ele estava realmente sendo injetado pelo spring, e realmente esta sendo injetado, mas qdo tento chamar um método, esta gerando uma exceção.
Alguém poderia me ajudar a resolver este problema?
Obrigado,