简体   繁体   English

为什么procedure()会报错

[英]Why does proceed() give an error

I have the following aspect: 我有以下几个方面:

aspect NullifyNoResultException {

    Object around(..) : execution(public Object com.example.*.*(..) {
        try { return proceed();    
            } catch (NoResultException e) { 
                return null;
            }                  
        }
    }
}

For some reason the call to proceed gives an error in Eclipse: 由于某种原因,继续进行的调用在Eclipse中产生了一个错误:

The method proceed() is undefined for the type NullifyNoResultException 对于类型NullifyNoResultException,未定义方法proceed()

When I build in maven -> mvn install I get no errors. 当我在maven-> mvn install构建时,没有任何错误。 But that makes no sense because I'm still missing an import for the NoResultException so maven should complain about that. 但这没有任何意义,因为我仍然缺少NoResultException的导入,因此行家应该抱怨一下。
Instead it just builds and does not complain. 相反,它只是构建而不会抱怨。

How do I get Eclipse to stop complaining about the proceed() ? 如何使Eclipse停止抱怨proceed()
and how do I get this aspect to build? 以及如何建立这个方面?

I found a few syntax errors in your code example. 我在您的代码示例中发现了一些语法错误。 When I correct them, the following example runs fine. 当我更正它们时,以下示例运行良好。 BTW, I defined my own NoResultException because I have no Java EE installed. 顺便说一句,我定义了自己的NoResultException因为我没有安装Java EE。

package javax.persistence;

public class NoResultException extends RuntimeException {
    private static final long serialVersionUID = 1L;
}
package com.example.stackoverflow;

import javax.persistence.NoResultException;

public class Application {
    public static void main(String[] args) {
        Application app = new Application();
        System.out.println(app.valueReturningMethod(1, "two"));
        System.out.println(app.exceptionThrowingMethod(1, "two"));
    }

    public Object valueReturningMethod(int i, String string) {
        return "normal result";
    }

    public Object exceptionThrowingMethod(int i, String string) {
        throw new NoResultException();
    }
}
package com.example.stackoverflow;

import javax.persistence.NoResultException;

aspect NullifyNoResultException {
    Object around() : execution(public Object com.example..*(..)) {
        try {
            return proceed();
        } catch (NoResultException e) {
            return null;
        }
    }
}

The output is as expected: 输出是预期的:

normal result
null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM