我正在使用CTW AspectJ,并且我试图将一个字段注入到我的方面中。注入字段总是返回null。
我使用了基于Java的配置:@Configuration @EnableAspectJAutoProxy(proxyTargetClass=true) public class ServicesConfig..
Spring本身是使用org.springframework.web.context.support.AnnotationConfigWebApplicationContext加载的
据我所知,我的方面不是使用Spring框架实例化,而是通过aspectj实例化。用Spring加载方面缺少什么?
我的方面看起来是这样的:
@Aspect
public class MyAspect {
@Inject
private SomeBean someBean;
@Around("execution(* com.mypackages..*(..))")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
Object result = null;
//some Aspect logic
return result;
}
}这就是bean的实例化方式,如果我尝试在应用程序中的其他地方@inject它,我将获得bean。
@Named
@Scope(value = "prototype")
public class SomeBean{
//bean logic
}发布于 2015-06-07 13:25:05
Spring-AspectJ with CTW的文档可以在here上找到。请注意,您必须使用@Configurable注释您的@Aspect。考虑到您可能错过了构建阶段或其中的一部分。我的意思是,您必须包含spring-aspects.jar作为方面库(无论您使用的是Maven还是Ant)。
此外,您还可以在here中找到好的示例/答案
https://stackoverflow.com/questions/30655530
复制相似问题