title: Inherit @Component in Spring
body: <p>I have a hierarchy of classes. I want mark them with <a href="https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/stereotype/Component.html" rel="noreferrer">@Component</a>. I'm trying to mark only the parent class. I expect Spring will mean childs as components too. But it doesn't happen.</p>
  
  <p>I tried to use custom <code>@InheritedComponent</code> annotation like described <a href="https://stackoverflow.com/questions/6912330/cant-get-component-to-be-inherited-in-spring">here</a>. It doesn't work.</p>
  
  <p>I wrote an unit test. It fails with: <code>"No qualifying bean of type 'bean.inherit.component.Child' available"</code>. Spring version is 4.3.7.</p>
  
  <pre><code>@Target(ElementType.TYPE)
  @Retention(RetentionPolicy.RUNTIME)
  @Component
  @Inherited
  public @interface InheritedComponent {}
  
  @InheritedComponent
  class Parent { }
  
  class Child extends Parent {
  }
  
  @Configuration
  @ComponentScan(basePackages = "bean.inherit.component")
  class Config {
  }
  
  @RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = Config.class)
  public class InheritComponentTest {
  
      @Autowired
      private Child child;
  
      @Test
      public void name() throws Exception {
          assertNotNull(child);
      }
  }
  </code></pre>