title: Spring Aspect doesn't work if bean is instantiated manually first
body: <p>I have a simple aspect like below</p>
  
  <pre><code>@Aspect
  public class PersistentAspect {
  
      @AfterReturning("@annotation(org.aspect.PersistentOperation)")
      public void log(JoinPoint jp) {
          System.out.println("aspect call");
      }
  
  }
  </code></pre>
  
  <p>and an <code>AppConfig</code> like below</p>
  
  <pre><code>public class AppConfig {
  
      private Integer num;
      private String text;
  
      public Integer getNum() {
          return num;
      }
  
      @PersistentOperation
      public void setNum(Integer num) {
  
          this.num = num;
      }
  
      public String getText() {
          return text;
      }
  
      @PersistentOperation
      public void setText(String text) {
  
          this.text = text;
      }
  
  }
  </code></pre>
  
  <p>And configuration class like below</p>
  
  <pre><code>@EnableWs
  @Configuration
  public class WsConfig extends WsConfigurerAdapter {
  
      @Override
      public void addInterceptors(List&lt;EndpointInterceptor&gt; interceptors) {
          AppConfig config = config();
          interceptors.add(new CustomValidatingInterceptor(schema(), null));
      }
  
      @Bean
      public AppConfig config() {
          AppConfig config = null;
          config = new AppConfig();
          return config;
      }
  
      @Bean
      public PersistentAspect persistentAspect() {
          PersistentAspect persistentAspect = new PersistentAspect();
          return persistentAspect;
      }
  }
  </code></pre>
  
  <p>If I use below in the <code>addInterceptors</code></p>
  
  <pre><code>AppConfig config = config();
  </code></pre>
  
  <p>The <code>Aspect</code> will not work. The obvious solution I have is to change the code to </p>
  
  <pre><code>AppConfig config = new AppConfig();
  </code></pre>
  
  <p>Now what I want to understand is, is there a config in which <code>AppConfig config = config();</code> could still be made working. I assume that when spring initiates the Bean, it can make an AOP proxy of the <code>AppConfig</code>, and when I initiate the bean it interferes with that process somehow. What is the spring/spring-boot way of handling this?</p>
  
  <p>Below is the <code>pom.xml</code>, so basically latest <code>Spring 5.0.5</code></p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web-services&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-aop&lt;/artifactId&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p><strong>Edit-1</strong></p>
  
  <p>Before posting the I had already adding a <code>@EnableAspectJAutoProxy</code>, but that had not helped. </p>
  
  <p>The git repo to try the issue is on below</p>
  
  <p><a href="https://github.com/tarunlalwani/spring-aop-so-50084308" rel="nofollow noreferrer">https://github.com/tarunlalwani/spring-aop-so-50084308</a></p>