我试图得到一个简单的AOP例子工作在我的IDE。
下面是我的代码。
我在下面得到这个错误。
请帮我理解为什么…
BeanCreationException:创建名为org. springframe.context.event.interentListenerProcator的bean时出错:bean的初始化失败;嵌套异常是java.lang.IllegalArgumentException:在org.springframework.beans.factory.support的切入点中::0 正式未绑定时出错。AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)~[spring-beas-4.3.18.RELEASE.jar:4.3.18.RELEASE]
AotSpringMain
@SpringBootApplication
public class AotSpringMain {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(AotSpringMain.class, args);
HumanFactory humanFactory = (HumanFactory)ctx.getBean("humanFactory");
System.out.println(humanFactory.getFemale().getName());
humanFactory.getFemale().setName("aaa");
System.out.println(humanFactory.getFemale().getName());
}
}
LoggingAspect
@Aspect
@Component
public class LoggingAspect {
@Before("execution(* com.my_aop_example.HumanFactory.*(..))")
public void logBefore(JoinPoint joinPoint, Object result) {
System.out.println("Log before start");
System.out.println("Name: " + joinPoint.getSignature().getName());
System.out.println("Log before end");
}
}
人力工厂
package com.my_aop_example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@Service
public class HumanFactory {
@Autowired
@Qualifier("Male")
Human Male;
@Autowired
@Qualifier("Female")
Human female;
public Human getMale() {
return Male;
}
public Human getFemale() {
return female;
}
没有参数对象结果
@Before("execution(* com.my_aop_example.HumanFactory.*(..))")
public void logBefore(JoinPoint joinPoint) {
System.out.println("Log before start");
System.out.println("Name: " + joinPoint.getSignature().getName());
System.out.println("Log before end");
}