Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未执行的方面_Java_Spring_Aspectj_Spring Aop - Fatal编程技术网

Java 未执行的方面

Java 未执行的方面,java,spring,aspectj,spring-aop,Java,Spring,Aspectj,Spring Aop,我们对函数有如下注释 public class AnInterfaceImpl implements AnInterface { @FairThreadUsageByEntity(entityName = "XYXYXYX", numberOfThreads = 1) public Report getReport(final String One, final String Two) { //implementation. } } public

我们对函数有如下注释

public class AnInterfaceImpl implements AnInterface {
    @FairThreadUsageByEntity(entityName = "XYXYXYX",
    numberOfThreads = 1)
    public Report getReport(final String One, final String Two) {
        //implementation.
    }
}

public interface AnInterface {
    String BEAN_NAME = "AnInterface";   //used for injection in spring.
    Report getReport(final String One, final String two);
}
弹簧配置:

<aop:aspectj-autoproxy />
<bean class="com.amazon.utils.fairthreadusage.aspect.FairThreadUsageByEntityAdvice" />
注释不知何故不起作用。我使用的是AspectJweaver1.7和Java1.7。 如果还需要什么,请告诉我。谢谢你的帮助

编辑:添加调用getReport函数的控制器

public class ReportDownloadRootController extends BaseRootController {
    public static final String REQUEST_MAPPING_REPORT_DOWNLOAD = "/hz/inventory/addproducts/status/report";
    public static final String PARAM_REFERENCE_ID = "reference_id";
    private AnInterface anInterface;

    @RequestMapping(REQUEST_MAPPING_REPORT_DOWNLOAD)
    public void execute(@RequestParam(value = PARAM_REFERENCE_ID, required = true) final String referenceId,
        final HttpServletRequest request, final HttpServletResponse response) {
        try {

            Report report = AnInterface.getReport(referenceId, getContext().getMerchantId());    //breakpoint here
        } catch {
            //something
        }
    }
    @Resource(name = AnInterface.BEAN_NAME)
    public void setAnInterface(final AnInterface anInterface) {
        this.anInterface = anInterface;
    }
}
编辑2:Springbean用于接口

<bean id="AnInterface" class="com.facade.feed.AnInterfaceImpl" />

我用您提供的所有信息创建了一个简单的项目,无法在简单的设置中重现您的问题,因此您有正确的bean/aspect实现


一个可能且常见的错误是在一个上下文中定义方面,在另一个上下文中定义bean,例如在
applicationContext
中定义方面,在
dispatcherServletContext
中定义bean。在这种配置中,aspect将无法在child
dispatcherServletContext
中定义的bean上工作,只有在父级
applicationContext

中才能工作,因为您使用的是普通JDK代理,而它们无权访问代理对象。如果您将
更改为
以使用CGLIB,会发生什么情况?@MikeKobit也没有尝试过这个选项。参考:由于您使用的是Spring AOP,我不确定您使用
AspectJWeaver-1.7
是什么意思。
允许您对AOP代理使用
@Aspect
样式的注释。你能通过设置断点来验证你的呼叫是否是a)通过代理进行的,b)你的建议是否被检查?@MikeKobit请查看编辑。我认为它澄清了更多的事情。我在调用get report的点上放置了一个断点。名为
Clib2AOPProxy
的类在调用
getReport
之前进行拦截,但没有检查建议。InterfaceImpl.getReport(…)上的注释应该是
@FairThreadUsageByEntity
,非
@ananotation
。这只是一个复制粘贴问题,还是您真的使用了错误的注释?
<bean id="AnInterface" class="com.facade.feed.AnInterfaceImpl" />