- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 Spring,我在对带注释的 Aspect 类进行依赖项注入(inject)时遇到了一些问题。 CacheService是在Spring上下文启动时注入(inject)的,但是当编织发生时,它说cacheService为空。所以我被迫手动重新查找 spring 上下文并从那里获取 bean。还有其他方法吗?
这是我的方面的示例:
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;
}
}
最佳答案
由于切面是在 Spring 容器之前创建的,因此您必须从切面的工厂方法aspectOf(ExampleClass.class) 中检索切面。
从 Spring XML 配置中,您可以像这样检索方面(对象):
<bean id="traceAspect" class="aspects.trace.TraceAspect"
factory-method="aspectOf" />
工厂方法是检索在 Spring 容器外部创建的对象(如 Enum)的常规方法。
关于Spring依赖注入(inject)带注释的Aspect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1343952/
在html中我可以设置背景图片的下面属性吗?(图片在iOS中我可以像下面这样设置图片的填充属性,但我不知道html中是否有类似的属性): Scale to Fill, Aspect Fit, Aspe
我一直在我的 OpenCV 和 OpenGL 组件之间来回切换,我不确定这两者中的哪一个应该更正这个问题。 使用 OpenCV 相机校准产生 fx、fy,纵横比大约为 1,这对应于正方形大小的图像。我
我正在使用 Perf4j 进行性能日志记录。 它指定您使用 aop.xml 来定义要在编译时调用哪个方面,具体取决于您使用的日志系统。我无法让它获取 src/main/webapp/meta-inf/
下方的分享图标(图片为白色)为 114x128 像素。 不过,使用 AutoLayout 将 Interface Builder 中的高度固定为 23 像素,然后对 Content Mode 使用 A
我正在尝试编写一个简单的 Spring Rest Web 服务,因为我不熟悉 Maven(并且因为 Maven 通常无法完成工作 - 连接问题),所以我现在正在尝试 ant 构建。现在,构建正常,服务
我使用网格和Flexbox布局了以下元素:。我希望在2x2的网格中布局.int元素,而.square元素的纵横比保持为1。。到目前为止,我有以下几个css:。如果视区的宽度大于高度(例如,横向),则可
I have the following elements laid out using both Grid and Flexbox:我使用网格和Flexbox布局了以下元素: <div
我在 UITableViewCell 中使用了 UIImageView,它将填充 contentView。我尝试了不同的模式,如“缩放以填充”、“Aspect Fit”、“” Aspect Fill”
我有一个方面排序列表。 public override void OnInvoke(MethodInterceptionArgs args) { args.Proceed(); var
我发现 Instagram 有一个像 300*300 这样的摄像头窗口?它是一个正方形,然后我尝试使用 GPUImage 制作相同的摄像头尺寸。所以我这样写: primaryView = [GPUIm
我一直致力于向 Spring MVC webapp 添加方面,但方面没有执行。我试图把它归结为一些简单的东西,显然应该可以工作,但仍然不行。这是我现在所处的位置: // imports... @Asp
我有一个运行特定逻辑的@After java 方面。我需要它返回一个结果(一个对象),该结果可以在方面切入点拦截的方法中使用。是否可以? 最佳答案 您需要的是@Around,它允许您将想要的任何内容返
SpringBoot@Aspect 打印访问请求和返回数据 为什么要用aspect, 使用aspect 可以使记录日志的功能面向切面,这样可以降低代码的耦合性。提供了两种方式对输入输出的数据进行打
我想从业务类中的方法访问局部变量,在方面类中的方法中。例如 class BusinessClass { public void simpleTest() { ...
我尝试使用 @Aspect 来记录所有请求和响应。如果我的端点有 @RequestBody,我的代码正在运行,但我的 get 端点没有 @RequestBody 并且我看不到日志。这是对这种情况的任何
我在学习AOP时遇到了一个场景。 所有类都在包com.spring内和Pointcut定义@AfterReturning Advice 的类型对于任何包类中的任何方法 com.spring具有任意数量
我是 alfresco 新手,我想创建一个能够提取自定义方面属性元数据的程序,我发现有人在谈论 Alfresco opencmis 扩展,但我不知道如何使用它,有吗我可以遵循教程吗? 最佳答案 如果您
你好我正在尝试使用 spring 注释和 AspectJ 实现一个方面但我不断收到错误 Aspect无法解析为类型 这是我的 pom.xml : org.spri
在我的网络系统中,我有一个像这样的 AppConfig 类 @Configuration @ComponentScan(basePackages = "com.mypackage") @EnableW
我有一个带有 spring 配置的应用程序服务器-客户端 RMI。现在我不会使用 @Aspect 添加方法调用日志记录。 我在 spring-context.xml 中添加了: 我的logger
我是一名优秀的程序员,十分优秀!