Bin inheritance in Spring



  • I tried to create two bins:

    @Component class A{...}
    

    @Component class B extends A{...}

    but not at all. autowire- there's a mistake.

    No qualifying bean of type is define: expected single matching bean bu found 2

    What do I do if I have to inherit one bin from another?



  • How does Spring have to figure out where to use the bin? Either give the bin names and introduce specifics with help. @Qualifier:

    @Component("a") class A{...}
    

    @Component("b") class B extends A{...}

    @Autowired @Qualifier("b") A b;
    @Autowired @Qualifier("a") A a;

    A a1 = appContext.getBean("a");
    A b1 = appContext.getBean("b");

    or refuse @Autowired and reconfigure manually through the grid.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2