Spring Configuration
The Spring container requires configuration that defines beans and their
relationship within an application. Configuration can be provided in the form
of XML,
annotations, or java code. XML configuration is commonly used due
to its intuitive nature, but it’s susceptible to refactoring
errors because the names
of classes and packages often change. Annotations provide an alternative
to XML, but the resulting configuration is decentralized and any changes require
modifications to the source code. Java configuration
files combine the
centralized configuration of XML with the convenience of annotations, but it
lacks some of the flexibility that XML provides.
Spring Lifecycle
The Spring container begins by instantiating an ApplicationContext with
one of the available configuration options. The container instantiates all of the
beans and injects their dependencies
via constructor injection, setter injection,
or reflection. Finally, the container invokes callback methods on beans that hook
into the lifecycle of the container. For example, the
container will invoke the
afterPropertiesSet()
method on any bean that implements the
InitializingBean
interface.