title: Spring boot @Configurable
body: <p>I'm trying to configure <code>Autowired</code> in non-spring managed class under spring boot application.
  I run successfully this under web application deployed under tomcat server.
  But when i want run this under spring boot nothing works.</p>
  
  <p>I made very simple app to check this functionality:</p>
  
  <p>Console result from web app int tomcat:</p>
  
  <pre><code>...:::TEST CONTROLLER
  ...:::TEST autowired in cotrnoller: com.mycompany.test_aop.Test@30ea7445
  ...:::NEW
  ...:::Check: com.mycompany.test_aop.Test@30ea7445
  </code></pre>
  
  <p>Console result from spring boot app:</p>
  
  <pre><code>...:::TEST CONTROLLER
  ...:::TEST autowired in cotrnoller: com.mycompany.test_aop.Test@627ae77d
  ...:::NEW
  ...:::Check: null
  </code></pre>
  
  <p>I read a lot of topics hot to configure spring boot app but nothing works.</p>
  
  <p>I trying set param -javaagent to spring-instrument.jar but no effect.</p>
  
  <p>I struggle with this for three days but no effect</p>
  
  <p><strong>App:</strong></p>
  
  <p>pom.xml:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;pl.com.eurohost&lt;/groupId&gt;
      &lt;artifactId&gt;aop_test&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;unknown-jars-temp-repo&lt;/id&gt;
              &lt;name&gt;A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.&lt;/name&gt;
              &lt;url&gt;file:${project.basedir}/lib&lt;/url&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
      &lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
              &lt;version&gt;1.3.3.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
  
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
              &lt;version&gt;1.3.3.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
              &lt;version&gt;1.3.3.RELEASE&lt;/version&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;version&gt;1.3.3.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
  
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
              &lt;version&gt;1.3.3.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-json&lt;/artifactId&gt;
              &lt;version&gt;1.19&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-servlet&lt;/artifactId&gt;
              &lt;version&gt;1.19&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;1.3.3.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-aspects&lt;/artifactId&gt;
              &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
              &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
              &lt;artifactId&gt;aspectjweaver&lt;/artifactId&gt;
              &lt;version&gt;1.8.6&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-instrument&lt;/artifactId&gt;
              &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
              &lt;version&gt;1.3.3.RELEASE&lt;/version&gt;
              &lt;type&gt;pom&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-agent&lt;/artifactId&gt;
              &lt;version&gt;2.5.6.SEC03&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
      &lt;/properties&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.3.3.RELEASE&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;repackage&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Main.class:</p>
  
  <pre><code>package com.mycompany.test_aop;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.EnableAspectJAutoProxy;
  import org.springframework.context.annotation.EnableLoadTimeWeaving;
  import org.springframework.context.annotation.aspectj.EnableSpringConfigured;
  import org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver;
  
  @SpringBootApplication
  @EnableSpringConfigured
  @EnableAspectJAutoProxy
  @EnableLoadTimeWeaving
  @ComponentScan(value = "com.mycompany.test_aop")
  public class Main {
  
      public static void main(String args[]) {
          SpringApplication.run(Main.class, args);
      }
  
      @Bean
      public InstrumentationLoadTimeWeaver loadTimeWeaver() throws Throwable {
          InstrumentationLoadTimeWeaver loadTimeWeaver = new InstrumentationLoadTimeWeaver();
          return loadTimeWeaver;
      }
  }
  </code></pre>
  
  <p>Web.java:</p>
  
  <pre><code>package com.mycompany.test_aop;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.ResponseBody;
  
  @Controller
  public class web {
      @Autowired
      Test t;
  
      @RequestMapping(value = "/")
      public @ResponseBody String root(){
          System.out.println("...:::TEST CONTROLLER");
          System.out.println("...:::TEST autowired in cotrnoller: "+t);
          Test2 a = new Test2();
          a.check();
          return "HI!";
      }
  }
  </code></pre>
  
  <p>Test.java:</p>
  
  <pre><code>package com.mycompany.test_aop;
  
  import org.springframework.stereotype.Service;
  
  
  @Service
  public class Test {
      public void display() {
          System.out.println("...:::TEST CLASS CALL DISPLAY");
  
      }
  }
  </code></pre>
  
  <p>Test2.java</p>
  
  <pre><code>package com.mycompany.test_aop;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Configurable;
  
  @Configurable
  public class Test2 {
      @Autowired
      private Test t;
  
      public Test2() {
          System.out.println("...:::NEW");
      }
  
      public void check() {
          System.out.println("...:::Check: "+t);
      }
  
  
  }
  </code></pre>
  
  <p><strong>Webapp has different pom, addittional file app-servlet.xml and no main method:</strong></p>
  
  <p>Main.java</p>
  
  <pre><code>package com.mycompany.test_aop;
  
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.EnableLoadTimeWeaving;
  import org.springframework.context.annotation.aspectj.EnableSpringConfigured;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  
  @EnableSpringConfigured
  @EnableLoadTimeWeaving
  @ComponentScan(value = "com.mycompany.test_aop")
  @Configuration
  @EnableWebMvc
  public class Main extends WebMvcConfigurerAdapter {
  
  
  }
  </code></pre>
  
  <p>app-servlet.xml:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:mvc="http://www.springframework.org/schema/mvc"
         xsi:schemaLocation="
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"&gt;
  
  
      &lt;mvc:default-servlet-handler/&gt;
  
      &lt;context:annotation-config/&gt;
      &lt;bean class="com.mycompany.test_aop.Main"/&gt;
  
  
      &lt;mvc:annotation-driven&gt;
      &lt;/mvc:annotation-driven&gt;
  
  &lt;/beans&gt;
  </code></pre>