Dependant Check : IoC Injection « Spring « Java






Dependant Check

/*
Pro Spring
By Rob Harrop
Jan Machacek
ISBN: 1-59059-461-4
Publisher: Apress
*/


///////////////////////////////////////////////////////////////////////////////////////
//File: depcheck.xml
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="simpleBean1" class="SimpleBean" dependency-check="simple">
        <property name="someInt">
            <value>16</value>
        </property>
    </bean>  
    
    <bean id="simpleBean2" class="SimpleBean" dependency-check="objects">
        <property name="nestedSimpleBean">
            <ref local="nestedSimpleBean"/>
        </property>
    </bean>  
    
    <bean id="simpleBean3" class="SimpleBean" dependency-check="all">
        <property name="someInt">
            <value>16</value>
        </property>
    </bean>    
    
    <bean id="nestedSimpleBean" class="SimpleBean"/>
</beans>
///////////////////////////////////////////////////////////////////////////////////////

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class SimpleBean {

    private int someInt;

    private SimpleBean nestedSimpleBean;

    public void setSomeInt(int someInt) {
        this.someInt = someInt;
    }

    public void setNestedSimpleBean(SimpleBean nestedSimpleBean) {
        this.nestedSimpleBean = nestedSimpleBean;
    }

    public static void main(String[] args) {
        BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
                "build/depcheck.xml"));
        
        SimpleBean simpleBean1 = (SimpleBean)factory.getBean("simpleBean1");
        SimpleBean simpleBean2 = (SimpleBean)factory.getBean("simpleBean2");
        SimpleBean simpleBean3 = (SimpleBean)factory.getBean("simpleBean3");
    }
}

           
       








DependantCheck.zip( 1,196 k)

Related examples in the same category

1.Simple Inject By ID
2.Simple Inject By Name
3.Auto Wiring
4.Hello World Xml With DI
5.Lookup Performance
6.Model View Injection in Spring