java - Spring not able to create bean -


i beginner spring , concepts. trying use @configuration , package-scan annotations scan bean provider classes under single package. when @bean annotated method of 1 of class having same name @bean annotated method of different class, bean creation both classes doesnt happen. if change @bean annotated method name different name bean not created, both beans created. not able understand behaviour.

    @configuration     public class managementhelperprovider {         @bean         public managementhelper getinstance() {             return new managementhelper();         }     } 

if creating class below top bean managementhelper not created.

    @configuration     public class managementvalidatorprovider {         @bean         public managementvalidator getinstance() {             return new managementvalidator();         }     } 

if creating class below top bean managementhelper created.

    @configuration     public class managementvalidatorprovider {         @bean         public managementvalidator getinstancetwo() {             return new managementvalidator();         }     } 

case1:

bean1 created name getinstance.

bean2 created same name getinstance , bean1 overridden this.

case2:

bean1 created name getinstance.

bean2 created name getinstancetwo. no override, because no conflict in names.

if

 @bean(name="bean1")  

and

@bean(name="bean2")  

it work.

@configuration public class appconfig {     @bean     public transferservice transferservice() {         return new transferserviceimpl();     } } 

the above exactly equivalent following appconfig.xml:

<beans>     <bean name="transferservice" class="com.acme.transferserviceimpl"/> </beans> 

both result in bean named transferservice being available in beanfactory/applicationcontext, bound object instance of type transferserviceimpl:

transferservice => com.acme.transferservice 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -