'why jdk proxy could not be injected

I use Aspect like this:

@Aspect
@Component
public class DataSourceAspect {
    @Pointcut("@target(com.chen.dynamicsource.aspect.DataSource)")
    public void pointCut() {

    }

    @Before("pointCut()")
    public void doBefore(JoinPoint joinPoint) {}
}

And I add it to application.yml:

spring
  aop:
    proxy-target-class: false

When I run the application. I get the following error:

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'dispatcherServlet' could not be injected because it is a JDK dynamic proxy

The bean is of type 'com.sun.proxy.$Proxy67' and implements:
    org.springframework.context.ApplicationContextAware
    org.springframework.core.env.EnvironmentCapable
    org.springframework.context.EnvironmentAware
    javax.servlet.Servlet
    javax.servlet.ServletConfig
    java.io.Serializable
    org.springframework.aop.SpringProxy
    org.springframework.aop.framework.Advised
    org.springframework.core.DecoratingProxy

Expected a bean of type 'org.springframework.web.servlet.DispatcherServlet' which implements:

I know I can use statically evaluated pointcut designators like within () and change the value of proxy-target-class to true to avoid the problem. But I just want to know why jdk proxy could not be injected.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source