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) 評論(0)  編輯  收藏 所屬分類: java

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

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 民县| 东光县| 苗栗县| 县级市| 龙口市| 汶川县| 九龙县| 中江县| 云浮市| 泰宁县| 裕民县| 六枝特区| 孟州市| 育儿| 马龙县| 乡宁县| 小金县| 巨鹿县| 安多县| 泰来县| 十堰市| 涿州市| 和顺县| 全南县| 东阿县| 东源县| 巫溪县| 高雄市| 汽车| 沙河市| 兴安盟| 北川| 策勒县| 开江县| 普安县| 松阳县| 辉南县| 水城县| 鹰潭市| 兴海县| 新津县|