On the way learning spring 3

Spring-12 Factory Beans and Methods


static method in Class person

non-static method in personFactory

Spring-13 The P Namespace

注意Constructor 中的Arg 和建立的Bean之间的关系

p: tag 和 property tag 不要同时使用

Spring-14 Setting List Property

In beans.xml file

Insert constructor argument ----> (Right click constructor argument)Insert List Element ---->(Right click list element)Insert Value Element

    <bean id="basket"
        class="com.caveofprogramming.spring.test.FruitBasket">
    <constructor-arg value="patrick‘s basket"></constructor-arg>
    <constructor-arg>
        <list>
            <value>apple</value>
            <value>peach</value>
            <value>pear</value>
            <value>orange</value>
            <value>banana</value>
        </list>
    </constructor-arg>
    </bean>

 Difference between ‘set‘ and ‘list‘

‘set‘ remove duplicate value.

Spring-15 Lists of Beans

 beans.xml<bean id="jungle"
        class="com.caveofprogramming.spring.test.Jungle">
        <property name="largest" ref="elephant"></property>
        <property name="animals">
            <list>
                <ref bean="lion" />
                <ref bean="snake" />
                <ref bean="elephant" />
            </list>
        </property>
    </bean>
App.java

    Jungle jungle =(Jungle)context.getBean("jungle");

        System.out.println(jungle);
        

ResultLargest: Animal [name=Richard, type=elephant]
Others:
Animal [name=Igor, type=lion]
Animal [name=Bob, type=snake]
Animal [name=Richard, type=elephant]

Spring-16 Inner Beans

Wrong edition

<bean id="jungle" class="com.caveofprogramming.spring.test.Jungle">
        <property name="largest">
            <bean id="elephant" class="com.caveofprogramming.spring.test.Animal">
                <property name="name" value="Richard"></property>
                <property name="type" value="elephant"></property>
            </bean>                   (inner bean)
        </property>
        <property name="animals">
            <list>
                <ref bean="lion" />
                <ref bean="snake" />
                <ref bean="elephant" />   (This part need to be deleted)
            </list>
        </property>
    </bean>

Reason: If you got an bean defined as an inner bean, you cannot refer to it somewhere else

<bean id="jungle" class="com.caveofprogramming.spring.test.Jungle">
        <property name="largest">
            <bean id="elephant" class="com.caveofprogramming.spring.test.Animal">
                <property name="name" value="Richard"></property>
                <property name="type" value="elephant"></property>
            </bean>
        </property>
        <property name="animals">
            <list>
                <bean id="lion" class="com.caveofprogramming.spring.test.Animal">
                    <property name="name" value="Igor"></property>
                    <property name="type" value="lion"></property>
                </bean>

                <bean id="snake" class="com.caveofprogramming.spring.test.Animal">
                    <property name="name" value="Bob"></property>
                    <property name="type" value="snake"></property>
                </bean>
            </list>
        </property>
    </bean>

 Spring-17 Property map

Insert property(foods)--->Insert props--->Insert prop element

    <bean id="jungle" class="com.caveofprogramming.spring.test.Jungle">
        <property name="foods">

        <props>
            <prop key="monkey">banana</prop>
            <prop key="panda">bamboo</prop>
            <prop key="snake">eggs</prop>
        </props>
        </property>
    </bean>

Spring-18 Arbitrary Maps as Bean Properties

Insert property(animals)--->insert Map--->insert Entity(entity key : lion   value-ref: lion)

<bean id="jungle"
        class="com.caveofprogramming.spring.test.Jungle">
        <property name="foods">

        <props>
            <prop key="monkey">banana</prop>
            <prop key="panda">bamboo</prop>
            <prop key="snake">eggs</prop>
        </props>
        </property>
        <property name="animals">
            <map>
                <entry key="lion" value-ref="lion"></entry>
                <entry key="snake" value-ref="snake"></entry>
                <entry key="elephant" value-ref="elephant"></entry>
            </map>
        </property>
    </bean>
时间: 2024-10-20 02:20:07

On the way learning spring 3的相关文章

On the way learning spring 2

Spring 10 - Bean scope Prototype; Request ;Session; Singleton. Source Code: Person person1 = (Person) context.getBean("person"); Person person2 = (Person) context.getBean("person"); person1.setTaxId(666); System.out.println(person2); R

On the way learning spring 4

Spring-19 Auto-Wiring  by type 在Xml文件中定义bean之间的关系时,有3种方法: 1. inner bean 2. 在bean 的property中定义另外一个bean 3. Spring Autowiring(有很多种类型, 这里 by type) <bean id="logger" class="com.caveofprogramming.spring.test.Logger" autowire="byType&

On the way learning spring 5

Spring-24 Adding Support for Annotation-Based Wiring Namespace-->check 'context'-->In 'context' Insert <context:annotation-config> element <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.spring

learning spring for Init Project (一)

reference:https://spring.io/quickstart 内容概要: 1 .初始化工程: 首先打开Idea软件, File->New->Project,如下图所示: 选中上图Spring Assistant,这是一个插件用来初始化spring工程.点击上图下一步,如下图所示: 点击Next.如下图所示: 选中上图的Web->Spring Web,然后点击Next,如下图所示: 输入项目名称,选项工程存放路径,点击Next. 如下图所示: 等待工程自动下载相关的jar包

On the way learning spring 6

Spring-47 Adding an Update Method to the DAO public boolean update(Offer offer){BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(offer); return jdbc.update("update offers set name=:name,text=:text,email=:email where id =:id&

【深度学习Deep Learning】资料大全

转载:http://www.cnblogs.com/charlotte77/p/5485438.html 最近在学深度学习相关的东西,在网上搜集到了一些不错的资料,现在汇总一下: Free Online Books Deep Learning66 by Yoshua Bengio, Ian Goodfellow and Aaron Courville Neural Networks and Deep Learning42 by Michael Nielsen Deep Learning27 by

【转】The most comprehensive Data Science learning plan for 2017

I joined Analytics Vidhya as an intern last summer. I had no clue what was in store for me. I had been following the blog for some time and liked the community, but did not know what to expect as an intern. The initial few days were good – all the in

DEEP LEARNING 大满贯课程表

Reinforcement Learning post by ISH GIRWAN Courses/Tutorials Deep Reinforcement Learning, Spring 2017, by UC Berkeley: http://rll.berkeley.edu/deeprlcours... Reinforcement Learning, 2015, by UCL (David Siver): http://www0.cs.ucl.ac.uk/staff/d.si... ht

Spring的配置分别是xml和java style

# Spring-IoCSpring配置有两种方式xml和java style ## Spring · spring的IoC(控制反转)就是一个工厂模式变种,<br/> · spring核心就是IoC容器,实现这个容器的接口BeanFactory,BeanFactory是最核心的.最纯粹的<br/> 方法: <br/> getBean() <br/> 实现类: <br/> ApplicationContext <br/> · 简单工厂