1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

Spring interview questions

!!! Spring interview questions !!!

What are the types of Dependency Injection Spring supports with Example?



Setter Injection and Constructor Injection .

The two major flavors of Dependency Injection are Setter Injection (injection via JavaBean setters); and Constructor Injection (injection via constructor arguments). Spring provides sophisticated support for both, and even allows you to mix the two when configuring the one object.

Setter Injection Example :
XML ----
<bean id="createCreditCard" class="springexample.creditcardaccount.CreateCreditCardAccount">
<property name="smsInterface">
            <ref bean="sms" />
        </property>
        <property name="daoInterface">
            <ref bean="dao" />
        </property>
</bean>
Java Class : CreateCreditCardAccount : Setter and Getter
public SMSInterface getSmsInterface() {
        return smsInterface;
    }
    /**
     * @param smsInterface The smsInterface to set.
     */
    public void setSmsInterface(SMSInterface smsInterface) {
        this.smsInterface = smsInterface;
    }
    /**
     * @return Returns the daoInterface.
     */
    public DAOInterface getDaoInterface() {
        return daoInterface;
    }
    /**
     * @param daoInterface The daoInterface to set.
     */
    public void setDaoInterface(DAOInterface daoInterface) {
        this.daoInterface = daoInterface;
    }



Constructor Injection Example:
<bean id="orderService"
class="spring.OrderService">
<constructor-arg>
<ref bean="orderDAO">
</constructor-arg>
</bean>

Java Class : OrderService

public class OrderService{
private OrderDAO orderDAO;
public OrderService(OrderDAO orderDAO){
this.orderDAO=orderDAO;
}
}


Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy