为了账号安全,请及时绑定邮箱和手机立即绑定

尝试使用Java Spring AOP时抛出“ org.springframework.beans”

尝试使用Java Spring AOP时抛出“ org.springframework.beans”

忽然笑 2021-05-06 14:07:47
我试图在我的IDE上获得一个简单的AOP示例。下面是我的代码。我在下面收到此错误。请帮助我了解原因。org.springframework.beans.factory.BeanCreationException:创建名称为“ org.springframework.context.event.internalEventListenerProcessor”的bean时出错:bean的初始化失败;嵌套的异常是java.lang.IllegalArgumentException:在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)的切入点中:: 02正式未绑定的错误.jar:4.3.18.RELEASE]AotSpringMain@SpringBootApplicationpublic 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@Componentpublic 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;@Servicepublic class HumanFactory {    @Autowired    @Qualifier("Male")    Human Male;    @Autowired    @Qualifier("Female")    Human female;    public Human getMale() {        return Male;    }    public Human getFemale() {        return female;    }
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA贡献1818条经验 获得超3个赞

没有参数 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");


  }


查看完整回答
反对 回复 2021-05-26
  • 1 回答
  • 0 关注
  • 220 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信