尝试使用 Java Spring AOP 抛出 "org.springframework.beans.factory.BeanCreationException"
trying to use Java Spring AOP throws "org.springframework.beans.factory.BeanCreationException"
我正在尝试让一个简单的 AOP 示例在我的 IDE 上运行。
下面是我的代码。
我在下面收到这个错误。
请帮我理解为什么..
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]
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;
}
没有参数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");
}
我正在尝试让一个简单的 AOP 示例在我的 IDE 上运行。
下面是我的代码。
我在下面收到这个错误。
请帮我理解为什么..
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]
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;
}
没有参数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");
}