Я пробую простой пример target указателя pointcut в Spring AOP
Но я не уверен, чего мне здесь не хватает. Столкнувшись с ошибкой ниже.
BeanNotOfRequiredTypeException: ожидается, что bean-компонент с именем 'fooDao' имеет тип 'com.opensource.kms.FooDao', но на самом деле имеет тип 'com.opensource.kms. $ Proxy19 '
Класс FooDao
package com.opensource.kms;
import org.springframework.stereotype.Component;
interface BarDao {
String m();
}
@Component
public class FooDao implements BarDao {
public String m() {
System.out.println("implementation of m");
return "This is return value";
}
}
Класс аспектов
package com.opensource.kms;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class SecurityService {
@Pointcut("target(com.opensource.kms.FooDao)")
public void myPointCut() {}
@Before("myPointCut()")
public void beforeMethod() {
System.out.println("beforeMethod");
}
}
Класс конфигурации
package com.opensource.kms;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@Configuration
@EnableAspectJAutoProxy
@ComponentScan("com.opensource.kms")
public class JavaConfig {
}
MainApp Class
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(JavaConfig.class);
FooDao ob = ctx.getBean("fooDao", FooDao.class);
System.out.println("data -> "+ob.m());
ctx.close();
Может ли кто-нибудь помочь мне здесь, не уверен, какие шаги мне нужно обновить в приведенном выше коде, чтобы используйте целевой указатель.