yestodayHadRain
V2EX  ›  问与答

关于 Spring AOP 的一个问题

  •  
  •   yestodayHadRain · Jun 10, 2018 · 1447 views
    This topic created in 2898 days ago, the information mentioned may be changed or developed.
    最近学习 Spring AOP 遇到一个问题,想不明白 各位大佬们帮忙看下:

    当前有一个借口两个类, userDao 接口 userDaoImpl 实现类, 还有一个 切面类 Aspect, 在 userDaoImlp 类下 的 save 方法执行前 调用下 Aspect 类下的 log 方法, 然后在测试类中使用, 使用时用的注入的方式 为什么 用 UserDao 接收 spring 给出的类可以,但是用 UserDaoImpl 类型接收就会报错呢?

    配置文件中配置的是 userDaoImpl 这个类呀
    4 replies    2018-06-10 20:46:35 +08:00
    yestodayHadRain
        1
    yestodayHadRain  
    OP
       Jun 10, 2018
    另外我打印了下,Spring 的返回对象是 UserDaoImpl 类型的,如果是这个类型的 用这个类型接收不对吗?
    watzds
        2
    watzds  
       Jun 10, 2018 via Android
    Java 动态代理需要接口的吧
    LangInteger
        3
    LangInteger  
       Jun 10, 2018 via Android
    因为默认使用 jdk 实现的代理,是基于被代理对象接口的,可以设置为基于 cglib 的代理,ciglib 采用继承被代理类实现代理。
    yestodayHadRain
        4
    yestodayHadRain  
    OP
       Jun 10, 2018
    确实是这样,谢谢两位
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2873 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 11:02 · PVG 19:02 · LAX 04:02 · JFK 07:02
    ♥ Do have faith in what you're doing.