title: How to provide a default bean in Spring by condition?
body: <p>I'd like to provide a default bean by a custom jar. Only if the user implements a specific <code>abstract</code> class the default bean injection should be skipped.</p>
  
  <p>The following setup already works fine, except one thing: any injected classes within the <code>default</code> wired class are <code>null</code>! What might I be missing?</p>
  
  <pre><code>@Configration
  public class AppConfig {
      //use the default service if the user does not provide an own implementation
      @Bean
      @Conditional(MissingServiceBean.class)
      public MyService myService() {
          return new MyService() {};
      }
  }
  
  
  @Component
  public abstract class MyService {
      @Autowired
      private SomeOtherService other;
  
      //default impl of the method, that may be overridden
      public void run() {
          System.out.println(other); //null! Why?
      }
  }
  
  public class MissingServiceBean implements Condition {
      @Override
      public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
          return context.getBeanFactory().getBeansOfType(MyService.class).isEmpty();
      }
  }
  </code></pre>
  
  <p>The <code>MyService</code> bean is created and can also be injected. But contained classes are null.</p>
  
  <p>If I remove the <code>@Conditioanl</code> annotation everything works as expected.</p>