Spring Interview Questions
Q. What is Spring Framework, what is benefits of using Spring?
Spring is an open source framework created to address the complexity of enterprise application development.
*Lightweight container
*No App Server Dependent ? like EJB JNDI Calls
*Objects are created Lazily , Singleton - configuration
*Components can added Declaratively
Initialization of properties is easy ? no need to read from properties file
*Declarative transaction, security and logging service - AOP
application code is much easier to unit test
*With a Dependency Injection approach, dependencies are explicit, and evident in constructor or JavaBean properties
*Spring's configuration management services can be used in any architectural layer, in whatever runtime environment.
*Spring can effectively organize your middle tier objects
*not requires special deployment steps
Q. What is IOC(Inversion of Control), what is advantage of using this?
*Loose coupling: Components can added Declaratively so we can add and remove the components with out code change.
For Example :
<bean id="createCreditCard" class="springexample.creditcardaccount.CreateCreditCardAccount">
<property name="emailInterface">
<ref bean="email" />
</property>
<property name="smsInterface">
<ref bean="sms" />
</property>
<property name="daoInterface">
<ref bean="dao" />
</property>
</bean>
There are three components associated with createCreditCard.
Tommorow you don't want smsInterface so just remove the xml configuration.
<property name="smsInterface">
<ref bean="sms" />
</property>
*Not Required any singletons : Don't need to code for singleton class. Every class is by default singleton. you can make not singleton
by making singleton="false"
<bean id="sms" class="springexample.sms.SMS" singleton="false">
</bean>
*Objects are created Lazily .
*Initialization of properties is easy ? no need to read from properties file.
For Example:
<bean id="email" class="springexample.email.Email" >
<property name="smtpHost">
<value>smtp.sa.com</value>
</property>
</bean>
IOC Contained set the setter method of Email class. setSmtpHost(). You don't nned to read from properties file with extra coding.
*No App Server Dependent ? like EJB JNDI Calls
|