spring --wiring binding

          Containing your beans
          ??? Tere i sno single Spring container.Spring actually comes with two distince types of containers:Bean factories and Application

          contexts.Beyong there two basic types of contains .Srping come with sereral implementss of BeanFacotory and ApplicationContext.
          ? 1 introducing the BeanFactory
          ? There are several implementations of BeanFactory in Spring .But the most userful one is XmlBeanFactory,whick loads
          its bean based on the definitions contained in an xml file.
          ? Creat a XmlBeanFactory? BeanFactory factory=new XMLBeanFactory(new FileInputStream("beans.xml"));
          ?But at that time ,the BeanFactory does not initialize the bean ,it is loaded lazliy.
          ? Get the Bean :MyBean myBean=(MyBean)factory.getBean("myBean");
          ?When getBean() is called ,the factory will instantiate the bean and being setting the bean using dependency injection.
          ? 2 Working with an application context
          ?an ApplicationContextis prefered over a BeanFactory in nearly all application ,the only time you might consider using a BeanFactory

          are in circumtance where resource s are scarce.
          ?? Amony the many implements of ApplicationContext are three that are commonly used:
          ????? ClassPathXmlApplicationContext,FileSystemXmpApplicationContext,XmlWebApplicationContext.
          ?? ApplicationContext context=new ClassPathXmlApplicationContext("foo.xml");
          ?wiring the beans
          ? <beans>
          ??? <bean id="foo" class="com.springinaction.Foo" />
          ?</beans>
          ?Prototyping vs.singleton
          ?By default ,all Spring beans are singletons.When the container dispenses a bean it will always give the exact same instance of the????

          In this case ,you would want to define a prototype bean .Defining a prototype means that instead of defining a single bean.
          ???? <bean id="foo" class="com.springinaction.Foo"? single/>on="false" />
          Initialization and destruction
          ?? <bean id="foo" class="com.springinaction.Foo" init-method="setup" destory-method="teardown">
          Injectiong dependencies via setter method
          ?? <bean id="foo" class="com.srpinginaction.Foo" >
          ??????? <property name="name">Foo McFoo</value>
          ?? </bean>
          ?Referencing other beans
          ?? <bean id="foo" class="com.springinaction.Foo">
          ???? <property name="bar" >
          ??????? <ref bean="bar" />
          ???? </property>
          ??? </bean>
          ??? <bean id="bar" colass="com.srpinginaction.Bar" />
          ?Inner beans
          ?? <bean id="courseService"
          ???????????? class="com.CourseWericeImpl">
          ???? <property nanme="studentService">
          ???????? <bean
          ????????????? class="com....." />
          ????? </property>
          ?? </bean>
          ? Wiring collections
          ??? 1Wiring lists and arrays? java.util.List
          ????? <property name="barList">
          ?????????? <list>
          ??????????????? <value>bar1</value>
          ??????????????? <ref bean="bar2"/>
          ?????????? </lsit>
          ????? </property>
          ?? 2 Wiring set? java.tuil.Set
          ??? <property name="barSet">
          ????????? <set>
          ???????????????? <value>bar1</value>
          ???????????????? <ref bean="bar2" />
          ????????? </set>
          ?? </property>
          ?? 3 Wiring maps java.util.Map
          ?? <property name="barMap">
          ??????? <ebtry key="key1">
          ??????? <value>bar1</value>
          ?? </property>
          ? 4 Wiring propertyies
          ??? <property name="barProps">
          ???????? <props>
          ??????????? <prop key="key1">bar1</prop>
          ??????????? <prop key="key2">bar2</prop>
          ???????? </props>
          ??? </property>
          ? 5 Setting null values
          ?? <property name="foo"><null/><property>
          ?? injecting dependencies via constructor
          ?? <id="foo" class="com.springinaction.Foo">
          ??? <constructor-arg>
          ??????? <value>42<value>( <ref bean="bar">)
          ???? </constructor-arg>
          ??? <bean id="foo" class="com.springinaction.Foo">
          ?????? <constructor-arg>
          ??????????? <value>http://www.manning.com</value>
          ?????? </constructor-arg>
          ? <constructor-arg>
          ??????????? <value>http://www.manning.com</value>
          ?????? </constructor-arg>
          ?? </bean>

          posted on 2006-09-04 11:10 康文 閱讀(311) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): java

          <2006年9月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(1)

          隨筆分類(lèi)

          隨筆檔案

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 台中县| 昆明市| 正定县| 甘孜| 长葛市| 芷江| 且末县| 乐安县| 沾化县| 乐平市| 大足县| 剑阁县| 云梦县| 奉化市| 天镇县| 纳雍县| 嵩明县| 姜堰市| 民丰县| 徐州市| 当雄县| 滕州市| 肥乡县| 封丘县| 花莲县| 鄂尔多斯市| 凉山| 南陵县| 沾益县| 桃园市| 友谊县| 泰顺县| 上高县| 潮州市| 嘉鱼县| 菏泽市| 静安区| 诸暨市| 霍林郭勒市| 大庆市| 无极县|