Spring Core

                                                         Spring Core
Q. What is spring container?
A. A special software written in Java that provides execution environment for the spring beans of spring application is nothing but a spring container.
-> Spring container provides following services :
1. Controlling the fife cycle of spring beans.
2. Dependency resolution.
3. Infrastructural services.

Spring Bean

Spring container

JVM + core libraries

Operating System.

Q. Explain about depends and dependencies of a spring application.
A. A spring application is an object oriented system i.e. a collection of collaborating object.
-> Services request for object is known as dependent and service provider object is known as its dependency.
-> service request and service provider objects are associated usin "has-a" relationship.

Q. What is POJO?
A. Any Java class is said to be a POJO, if it does not inheriting from any framework specific or technology specific interface or class.

Q. What is the life cycle of Spring Bean?
A. A spring bean is a POJO(Plain Old Java Object). Spring container controls the life cycle of spring bean without any component control. A Spring Bean has 4 life cycle phase.
 1. Instantiation phase.
 2. Initialization phase.
 3. Ready-to-use phase.
 4. Destruction phase.

Instantiation phase: Spring container loads the spring bean into memory and create the instance of the bean. Spring container populating the fields implicitly based on the configuration
specified in configuration file.

Note: Spring container deals with instantiation of the spring bean based on the bean definition made in the bean configuration file or based on annotation mapping.

Initialization phase: Spring container invokes the custom initialization method if any of the spring bean. If any resource required for the spring bean, spring developer will provide
      to the bean through this init method. custom initialization method is any user defined method implemented in spring bean class and specified in configuration files.

Ready-to-use phase: After instantiating and initializing the spring bean, spring container dispenses it to its user, then it is said to be in ready-to-use state(phase).

Destruction phase: Spring container invokes the custom destroy method if any of the spring bean. If any resource given to the spring bean during its initialization phase are released
in this user defined method. custom destroy method is any user defined method implemented in spring bean class and specified in configuration file.

Q. How to register a spring bean with the spring container?
A. <bean name = "test" class="com.java.test.A" />

Comments