我试图在我的IDE上获得一个简单的AOP示例。
下面是我的代码。
我在下面收到此错误。
请帮助我理解原因。
org.springframework.beans.factory.BeanCreationException:创建名称为“ org.springframework.context.event.internalEventListenerProcessor”的bean时出错:bean的初始化失败;嵌套异常是java.lang.IllegalArgumentException:在切入点:: 0形式上未绑定的错误 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)〜[spring-beans-4.3.18.RELEASE.jar:4.3.18.RELEASE] < / p>
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");
}
}
HumanFactory
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;
}
答案 0 :(得分:1)
没有参数Object result
@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");
}