@Aspect
public class OrgManagerSynchronizer {
@Pointcut("execution(* com.alvin.OrgManager.getOrg(..))")
public void classMethods() {}
@Before("classMethods()")
public void synchronize(JoinPoint jp) {
//code should be executed. but does not execute.
}
}
在我的.xml中指定了这一点:
aop:aspectj-autoproxy
我还应该添加什么?下一步该怎么办?
检查事物下方1)检查orgmanagerimpl是否在上下文xml中为bean进行防御,或者标记为@component&在上下文xml中或您拥有的cassexs package.in
2)如果上面的事情是正确的,请尝试更改以下的尖端。@Pointcut("execution(* get*(..))")
该点键拦截所有方法。查看这一点是否削减了您的同步方法。如果起作用,则至少您的春季配置很好。您只需要完善尖端表达式即可。但是,如果这也不起作用,那么您的弹簧AOP配置本身会出现问题,因此我们可以专注于这些配置。
您需要检查两件事。
aop:在配置中启用了aptivej-autoproxy
点切数 /方面 /目标是弹簧豆
下面是我的XML配置示例。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<aop:aspectj-autoproxy/>
<context:component-scan base-package="com.techoffice"/>
<bean class="com.techoffice.example.ExampleAspect"/>
</beans>
package com.techoffice.example;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class ExampleAspect {
@Pointcut("execution (* com.techoffice..*(..))")
public void anyRun() {}
@Before(value="anyRun()")
public void beforeAnyRun(JoinPoint jointPoint){
System.out.println("Before " + jointPoint.getClass().getName() + "." + jointPoint.getSignature().getName());
}
@After(value="anyRun()")
public void afterAnyRun(JoinPoint jointPoint){
System.out.println("After " + jointPoint.getClass().getName() + "." + jointPoint.getSignature().getName());
}
}
package com.techoffice.example;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
@Component
public class HelloWorldExample {
public void run(){
System.out.println("run");
}
public static void main(String[] args){
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
HelloWorldExample helloWorldExample = context.getBean(HelloWorldExample.class);
helloWorldExample.run();
}
}