建议后的Spring AOP在getter函数上工作不正常

建议后的Spring AOP在getter函数上工作不正常,spring,aop,getter,pointcut,Spring,Aop,Getter,Pointcut,在Spring框架中,我在使用AOP时面临一个奇怪的问题。 我有以下用于问候语的简单bean类: public class HelloBean { private String message; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; }

在Spring框架中,我在使用AOP时面临一个奇怪的问题。 我有以下用于问候语的简单bean类:

public class HelloBean {
    private String message;
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void displayGreeting() {
        System.out.println("Hello");
    }
}
下面是spring配置:

测试等级:

输出:

问题:

当我使用getter作为切入点时,为什么在打印之前和之后都有建议。当我在displayGreeting方法上使用切入点时,建议工作正常???

System.out.println在hello.getMessage之后执行。您可以使用调试程序进行检查

1)preRunMessage()
2)hello.getMessage()
3)postRunMessage()
4)the System.out.println() prints the string returned by hello.getMessage()
尝试在hello.getMessage中打印某些内容,它将在pre和post RunMessage方法之间打印

public class ServiceCheck {

    public void preRunMessage() {
        System.out.println("Runs before the greeting");
    }

    public void postRunMessage() {
        System.out.println("Runs after the greeting");
    }
}
public class Test {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext(
                "spring-beans.xml");
        HelloBean hello = (HelloBean) context.getBean("hello");
        hello.setMessage("Hello World");
        System.out.println(hello.getMessage());

    }
}
Runs before the greeting
Runs after the greeting
Hello World
1)preRunMessage()
2)hello.getMessage()
3)postRunMessage()
4)the System.out.println() prints the string returned by hello.getMessage()