@EnableAspectJAutoProxy not work with proxyTargetClass=false

感情迁移 提交于 2019-12-05 12:27:45
@EnableAspectJAutoProxy(proxyTargetClass=false)

Indicates that JDK dynamic proxy will be created to support aspect execution on the object. And therefore as this type of proxy requires a class to implement an interface your MessagePrinter must implement some interface which declares method getMessage.

@EnableAspectJAutoProxy(proxyTargetClass=true)

On the opposite instruct to use CGLIB proxy which is able to create proxy for a class without an interface.

1> Message Printer has to be defined as a component i.e : `

 package com.pjcom.springaop.message.impl;
    @Component
    public class MessagePrinter{
    public void getMessage(){
    System.out.println("getMessage() called");
    }
    }`

in the same package as configuration java file if no @ComponentScan is not defined for some other packages.

2> If same type of bean class has many other dependencies then to resolve dependencies in spring Config use @Qualifier annotation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!