-
What is spring?Answer: Spring is an open source framework, which is light weight. It resolves commonly and repeatedly occurred problems. Spring is famous for its modularity, which means we can use only those parts of spring that we need to build our application. Rest of the parts can be ignored.
-
What is Inversion Of Control?Answer: Inversion of control or IoC is the core of spring framework. As the name suggests IoC manages java objects from construction to destruction. In other words it manages the life cycle of the object. For example, a person X is supposed to do a work. Instead of person X, person Y has done the work. The outcome of the person Y work is used by person X. We call this as "Inversion of Control". In struts we create the DAO object and call the methods. If we use spring IoC, spring is responsible to create DAO class object. Developer is responsible to call the methods of DAO.
-
What is Dependency Injection?Answer: Dependency Injection (DI) is a flavor of Inversion of Control. The inversion of control is more general concept and dependency injection is a concrete form of IoC. Dependency is a process whereby objects define their dependency. There are two ways using which dependency injection can be achieved in spring. One is Setter method injection and the other is using Constructor injection.
-
What is Aspect Oriented Programming or AOP?Answer: In simple words Aspect Oriented Programming (AOP) concept is similar to the triggers concept in data base. Using aspects Spring can add additional functionality to a method execution. This additional functionality could be before a method execution or after method execution.
-
What is autowiring?Answer: The Spring container provides the functionality of connecting beans with each other automatically. Instead of developer injecting one bean into the other using "ref" attribute, Spring can look into the BeanFactory and decide how to inject one bean into the other. This is called as autowiring.
-
What are the different modes of auto wiring?Answer: The autowiring functionality has five modes which can be used to instruct Spring container to use autowiring for dependency injection:
- no/default
- byName
- byType
- constructor
- autodetect
-
Explain the different bean scopes available in spring.Answer: There are different bean scopes that are available in spring. They are:
- singleton: When singleton scope is given, spring container will create only one instance for that bean.
- prototype: When prototype scope is given, spring container can create any number of instances.
- request: Request scopes a bean definition to a HTTP request.
- session: Session scopes a bean definition to a HTTP session
- global-session: Global-session scopes a bean definition to a global HTTP session.
-
Explain about lazy-init concept in spring.Answer: Whenever the spring container object is created based on application context it creates all the spring beans and establish the dependencies for all the beans whose scope attribute is default/singleton. If we do not want the spring container to create all the spring beans then we need to set lazy-init to "true". By default this value is "false". When lazy-init is set to "true" then spring container will not create object immediately even if scope is set to "singleton". To know more about lazy-init concept ... Click here
-
Explain bean life-cycle in spring Bean Factory Container.Answer: Bean life cycle in Spring Bean Factory Container is as follows:
- The spring container finds the bean’s definition from the XML file and instantiates the bean.
- Using the dependency injection, spring populates all of the properties as specified in the bean definition.
- If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID.
- If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.
- If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called.
- If an init-method is specified for the bean, it will be called.
- Finally, if there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called.
-
What does @Required annotation mean?Answer: The @Required annotation indicates that the affected bean property must be populated at configuration time, through an explicit property value in a bean definition or through autowiring.
-
What does @Autowired annotation mean?Answer: The @Autowired annotation can be used to autowire bean on a setter method or on a constructor or on any method with arbitrary name. This annotation gives developer more control over the code.
-
What does @Qualifier annotation mean?Answer: There may be a situation when you create more than one bean of the same type and want to wire only one of them with a property, in such case you can use @Qualifier annotation along with @Autowired to remove the confusion by specifying which exact bean will be wired.
-
Explain about java based configuration in spring.Answer: Spring has introduced java based configuration to make the task of the developer easy. A developer, instead of writing the configuration in an XML file, can provide the details in the classes where the logic is written with the help of annotations. For example, "@Bean" annotation tells the spring that a method annotated with @Bean will return an object that should be registered as a bean in the Spring application context.
-
Explain the different concepts in Aspect Oriented ProgrammingAnswer: There are different concepts in Aspect Oriented Programming. They are as follows:
- Aspect
- Join Point
- Advice
- Pointcut
- Introduction
- Target
- AOP proxy
- Weaving
-
Explain spring MVC architecture.Answer: The spring MVC architecture has been explained clearly at ... Spring MVC architecture
Spring interview questions and answers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment