Beanfactory can be understood as a factory class that contains bean collections. Beanfactory contains the definition of a bean to instantiate the corresponding bean when a client request is received.
Beanfactory can also generate relationships between collaboration classes when instantiating an object. This frees the bean itself from the configuration of the Bean client. The beanfactory also contains the Bean lifecycle control, the invocation of the client's initialization method (initialization methods), and the Destruction method (destruction methods).
On the surface, application context, like Bean factory, has a bean definition, bean affinity setting, and the ability to distribute beans on request. However, the application context also provides other features on this basis.
- Provides a text message that supports internationalization
- Unified resource File Read mode
- Events for beans that have been registered in the listener
Here are three more common ways to implement ApplicationContext:
1. Classpathxmlapplicationcontext: Reads the context from the classpath XML configuration file and generates a context definition. The application context is obtained from the program environment variable.
ApplicationContext context = new Classpathxmlapplicationcontext ("Bean.xml");
2. Filesystemxmlapplicationcontext: The context is read by the XML configuration file in the file system.
ApplicationContext context = new Filesystemxmlapplicationcontext ("Bean.xml");
3. Xmlwebapplicationcontext: The context is read by the Web application's XML file.
What's the difference between Beanfactory and ApplicationContext?