java - Spring @Autowired for setter methods vs non-setter methods -


according @autowired javadoc:

marks constructor, field, setter method or config method autowired spring's dependency injection facilities. 1 constructor (at max) of given bean class may carry annotation, indicating constructor autowire when used spring bean. such constructor not have public. fields injected right after construction of bean, before config methods invoked. such config field not have public. config methods may have arbitrary name , number of arguments; each of arguments autowired matching bean in spring container.

bean property setter methods special case of such a general config method. such config methods not have public. in case of multiple argument methods, 'required' parameter applicable arguments. in case of collection or map dependency type, container autowire beans matching declared value type. in case of map, keys must declared type string , resolved corresponding bean names. note actual injection performed through beanpostprocessor in turn means cannot use @autowired inject references beanpostprocessor or beanfactorypostprocessor types. please consult javadoc autowiredannotationbeanpostprocessor class (which, default, checks presence of annotation).

my question is, meant config methods? , also, let's have setter method @autowired annotation , arbitrary method @autowired annotation. assume setter method invoked spring automatically after bean instantiation, while random-named @autowred method won't invoked, right? how spring understand, @autowired method should invoked after instantiation (setters), while others shouldn't? , how correlate statement javadoc, saying

bean property setter methods special case of such general config method

where can read it, spring documentation doesn't have information on , wasn't able find exact logic used spring in javadocs.

@autowired annotation can used constructor, setter method or other method. whenever spring finds @autowired annotation try find beans matching method parameters , invoke method. if multiple methods (setter or non-setter) have @autowired annotation, invoked spring after bean instantiation.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -