53. What are the additional bean scopes apart from singleton and prototype?
The lifecycle of prototype bean is different than a singleton. When the container is asked to supply a prototype bean, it returns new instance, but the container does not hold on to it past that point. But for singleton container manages the life cycle.
Scopes a bean for a particular HTTP request. Only valid when used in a web capable Spring context(such as with Spring MVC).
57. What is sessions scope?
It is the scope of a bean for an HTTP session. It works only when used in a web capable Spring context(such as with Spring MVC).
58. What is global-session scope?
Scopes a bean for a global HTTP session. Only valid when used in a web capable Spring context(such as with Spring MVC).
59. What is wiring?
The wiring can be defined as a technique via which Spring creates an association between different components of an application.
60. What is autowiring?
Autowiring allows Spring to wire all bean properties automatically by setting the autowire property on each bean that you want autowired.
<bean id=”foo' class='com.a4academics.Foo” autowire=”autowire type”/>
61. What are the types of autowiring?
Four types of autowiring:
62. What is autowiring byName?
It is a technique by which a bean can be identified in the container whose name or id matches the property being wired.
63. What is autowiring byType?
It is a technique by which it matches all properties of the autowired bean with beans whose types are compatible.
64. What is autowiring by constructor?
It is a technique by which it matches a constructor of the autowired bean with beans whose types are compatible to the constructor arguments.
65. What is autowiring by autodetect?
If we assign autowire attribute to autodetect, then container decides the mode of autowiring to use.
66. What is configuration metadata in Spring IOC container?
Using configuration metadata we tell the Spring container as to how to instantiate, configure and assemble the objects in your application.This configuration metadata can be supplied in a simple XML format, annotation or Java code.
67.What is Resource interface?
An application needs to access a variety of resources in different forms, e.g. configuration data stored in a file in the file system, some image data stored in a jar file on the classpath. Spring provides a Resource interface to provide a unified mechanism for accessing resources in a protocol independent manner.
68. What are the implementation classes of Resource interface?
69. What is initialization and destruction in Spring container?
When a bean is created, we need to perform some initialization on the bean that can be done with initialization method. When the bean is removed from the container, some cleanup may be required on the bean which can be done with destruction method. Spring can use two life-cycle methods of each bean to perform this setup and teardown.
<bean id=”foo” class=”com.Spring.Foo” init-method=”setup” destroy-method=”teardown”/>
70. What is defaulting init-method and destroy-method?
When many beans in a configuration file has initialization or destroy methods with same name, you can declare default-init-method and default-destroy-method attributes on the <beans> element in the configuration file instead of declaring multiple init-method and destroy-method for all the beans.
71. What is InitializingBean interface?
It provides afterPropertiesSet() method which is called when the bean is initialized by the container.
72. What is DisposableBean interface?
It provides destroy() method which is called when the bean is disposed by the container.
73. What is the advantage of InitializingBean and DisposableBean interface?
The advantage is that Spring container is able to automatically detect beans without any external configuration.
74. What is the drawback of InitializingBean and DisposableBean interface?
The drawback is that the application beans are coupled with Spring API.
75. What is customizing beans with BeanPostProcessor?
BeanPostProcessor interface defines methods via which we can customize beans to provide our own custom logic for bean instantiation, dependency resolution etc.
76. What are the two interfaces provided by Spring for bean post processing?
These are BeanPostProcessor and BeanFactoryPostProcessor interface.