Contents
- 1 How do you handle shutdown of IoC container?
- 2 Which interface provides a mechanism to register objects that are created outside the container?
- 3 What is IoC and DI in Spring?
- 4 How do I initialize a bean instance in spring?
- 5 Can a IoC container be removed from a dependency graph?
- 6 What is the difference between iobjectfactory and iapplicationcontext?
How do you handle shutdown of IoC container?
So we need to ensure that after application is finished, destroy method on our beans should be called. In web-based application ApplicationContext already implements code to shut down the IoC container properly. But in desktop application we need to call registerShutdownHook to shutdown IoC container properly.
Which interface provides a mechanism to register objects that are created outside the container?
BeanFactory interface
The BeanFactory interface is the central IoC container interface in Spring. Its responsibilities include instantiating or sourcing application objects, configuring such objects, and assembling the dependencies between these objects.
How can the bean life cycle be controlled?
Spring framework provides following 4 ways for controlling life cycle events of a bean: InitializingBean and DisposableBean callback interfaces. *Aware interfaces for specific behavior. Custom init() and destroy() methods in bean configuration file.
What is dependency injection and IoC in spring?
IOC is technique where you let someone else to create the object for you. And the someone else in case of spring is IOC container. Dependency Injection is a technique where one object supplies the dependency of another object.
What is IoC and DI in Spring?
Inversion of Control(IoC) is also known as Dependency injection (DI). The Spring container uses Dependency Injection (DI) to manage the components that build up an application and these objects are called Spring Beans. IoC is also known as dependency injection (DI).
How do I initialize a bean instance in spring?
Using Annotation: To provide the facility to the created bean to invoke custom init() method on the startup of a spring container and to invoke the custom destroy() method on closing the container, we need annotate init() method by @PostConstruct annotation and destroy() method by @PreDestroy annotation.
Which is the IoC container in Spring Framework?
The IObjectFactory is the actual representation of the Spring IoC container that is responsible for instantiating, configuring, and managing a number of objects. The IObjectFactory interface is the central IoC container interface in Spring.
Can a IoC container be used in more than one class?
Whilst in general this philosophy may be a good idea, in the case of an IoC container used correctly, it is unnecessary and unproductive. This is because the IoC container should only be used in a single class at the root of your application.
Can a IoC container be removed from a dependency graph?
An IoC container should be there to assist in the building of dependency graphs and as we said previously, you should be able to remove the container and build your graph manually without requiring any changes to the code (other than the root class that starts the application).
What is the difference between iobjectfactory and iapplicationcontext?
In short, the IObjectFactory provides the configuration framework and basic functionality, while the IApplicationContext adds more enterprise-centric functionality to it.