gpt4 book ai didi

java - 尝试使用 Java Spring AOP 抛出 "org.springframework.beans.factory.BeanCreationException"

转载 作者:行者123 更新时间:2023-12-02 11:00:50 25 4
gpt4 key购买 nike

我正在尝试在我的 IDE 上运行一个简单的 AOP 示例。

下面是我的代码。

我在下面收到此错误。

请帮我理解为什么..

org.springframework.beans.factory.BeanCreationException:创建名称为“org.springframework.context.event.internalEventListenerProcessor”的bean时出错:bean初始化失败;嵌套异常是 java.lang.IllegalArgumentException: error at::0formal unbound in pointcut 在 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());

}
}

日志方面

@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");

}

关于java - 尝试使用 Java Spring AOP 抛出 "org.springframework.beans.factory.BeanCreationException",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51341491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com