Alternatively, you can have spring wire them automatically by setting the autowire Property
On each <bean> that you want autowired:
There are four types of autowiring:
■ Byname-attempts to find a bean in the container whose name (or ID) is the same as the name
Of the property being wired. If a matching bean is not found, then the property will remain
Unwired.
■ Bytype-attempts to find a single bean in the container whose type matches the type of
Property being wired. If no matching bean is found, then the property will not be wired. If
More than one bean matches,
Org. springrframework. Beans. Factory. unsatisfieddependencyexcpetion will be thrown.
■ Constructor-tries to match up one or more beans in the container with the parameters
One of the constructors of the bean being wired. In the event of ambiguous beans or
Ambiguous constructors, an org. springframework. Beans. Factory. unsatisfieddependencyexception
Will be thrown. (by type in constructor)
■ Autodetect-attempts to autowire by constructor first and then using bytype. ambiguity is
Handled the same way as with constructor and bytype wiring.
You can set a default autowiring for all beans within the spring configuration wiring File
By setting default-autowire on the Root <beans> element: <beans default-autowire = "byname">
Working with spring's special beans:
■ Become involved in the bean's and the Bean factory's life cycles by Postprocessing
Bean Configuration
■ Load configuration information from external Property Files
■ Alter spring's dependency injection to automatically convert string values to another type
When setting bean properties-for example, being able to inject a string value into
Java. util. Date field and have the date automatically converted
■ Load textual messages from property files, including internationalized messages
■ Listen for and respond to application events that are published by other beans and by
Spring container itself
■ Are aware of their identity within the spring container
The beanpostprocessor interface gives you two opportunities to alter a bean after it has
Been created and wired:
The postprocessbeforeinitialization () method is called immediately prior to Bean
Initialization (the call to afterpropertiesset () and the Bean's custom initmethod). Likewise,
The postprocessafterinitialization () method is called immediately after initialization.
The Spring framework itself uses several implementations of beanpostprocessor under
Covers. For example, applicationcontextawareprocessor is a beanpostprocessor that sets
Application context on beans that implement the applicationcontextaware interface.
While a beanpostprocessor performs postprocessing on a bean after it has been loaded,
Beanfactorypostprocessor performs postprocessing on a bean factory after the Bean Factory
Has loaded its bean definitions but before any of the beans have been instantiated.
Two very useful implementations of beanfactorypostprocessor are
Propertyplaceholderconfigurer and customeditorconfigurer
Propertyplaceholderpolicer loads properties from one or more external Property Files and
Uses those properties to fill in placeholder variables in the bean wiring XML file.
Customeditorconfigurer lets you register impm implementations of Java. Beans. propertyeditor
To translate property wired values to other property types.