day38 13-spring of the Bean's attributes: Spel injection

Source: Internet
Author: User

SPRING2.5 provides a way for the namespace p to inject properties, Spring3. Several provide a way to inject spel attributes.

<?XML version= "1.0" encoding= "UTF-8"?><!--don't go to Schema,schema is file, local file, you have to lead that head -<Beansxmlns= "Http://www.springframework.org/schema/beans"xmlns:p= "http://www.springframework.org/schema/p"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" ><!--demo1 Quick Start ================================================= -<!--The interface and implementation classes are configured in this configuration file, and the full path to the implementation class can be used for factory reflection. -      <!--use a <bean> tag to set the class's information, using the id attribute as an identifier for the class. -    <!--interfaces, implementation classes, and configuration files are also available. -    <!--now there is a factory spring for us to provide, in fact, is to parse this XML file -    <!--will you write this factory yourself? You use dom4j to find the bean tag inside, find the attribute value of class, and then you can class.forname () to generate an instance of the class. In fact spring did, but the factory was provided by spring.  -    <BeanID= "HelloService"class= "Cn.itcast.spring3.demo1.HelloServiceImpl">         <!--using the <property> Tag Injection property value refers to the normal value ref refers to the object -    < Propertyname= "Info"value= "Preach Intelligence podcast"></ Property>    </Bean>    <!--demo1 Quick Start -    <!--instantiation of the Demo2bean -    <!--by default, a parameterless construction method is used. -    <!--<bean id= "Bean1" class= "Cn.itcast.spring3.demo2.Bean1" ></bean> -    <!--<bean name= "Bean1" class= "Cn.itcast.spring3.demo2.Bean1" ></bean> -    <!--The second use of static factory instantiation cannot write class, because now spring does not create objects for you directly. -    <!--<bean id= "bean2" class= "Cn.itcast.spring3.demo2.Bean2Factory" factory-method= "getBean2" ></bean> /c8> -    <!--The third instance of using instance factory instantiation -    <!--<bean id= "bean3" factory-bean= "bean3factory " factory-method= "GetBean3" ></bean> -    <!--to instantiate the Bean3factory first -    <!--<bean id= "bean3factory" class= "Cn.itcast.spring3.demo2.Bean3Factory" ></bean> -    <!--instantiation of Demo2bean ====================== end -        <!--Demo3bean scope of action ======================= -    <!--<bean id= "Customer" class= "Cn.itcast.spring3.demo3.Customer" scope= "prototype" ></bean> -    <!--<bean id= "Product" class= "cn.itcast.spring3.demo3.Product" init-method= "Setup" destroy-method= "teardown" Scope= "Singleton" > <property name= "name" value= "Air Conditioning" > -       <!--inject the property name of the product class in -       <!--</property> </bean> -       <!--the life cycle of Demo4bean ======================= -       <!--<bean id= "customerservice" class= "Cn.itcast.spring3.demo4.CustomerServiceImpl" init-method= "Setup" Destro       y-method= "teardown" > <property name= "name" value= "Itcast" ></property> </bean>  -       <!--The post-processing bean is automatically called by the spring container without your tube, and we have an ID for us to get it in the program. But this class is not available to us and is automatically called by spring. Cn.itcast.spring3.demo4.MyBeanPostProcessor is a post-processing bean -        <!--<bean class= "Cn.itcast.spring3.demo4.MyBeanPostProcessor" ></bean> -       <!--Demo5bean Attribute Injection ============================================================================================= ======================================== -       <!--injection of construction methods -       <BeanID= "Car"class= "Cn.itcast.spring3.demo5.Car">        <Constructor-argname= "Name"value= "BMW"><!--Use this tag to inject properties into a class -        </Constructor-arg>        <Constructor-argname= "Price"value= "1000000"><!--Use this tag to inject properties into a class -        </Constructor-arg>        <!--<constructor-arg index= "0" type= "java.lang.String" value= "Mercedes" >--><!--Use this tag to inject properties into a class -        <!--</constructor-arg> -        <!--<constructor-arg index= "1" type= "java.lang.Double" value= "2000000" >--><!--Use this tag to inject properties into a class -                   <!--</constructor-arg> -       </Bean>       <!--<bean id= "car2" class= "Cn.itcast.spring3.demo5.Car2" > -       <!--in the <property> tag, name is the attribute name, value is the values of the normal property, ref: References other objects -       <!--<property name= "name" value= "Porsche Chery QQ" ></property> <property name= "Price" value= "50000002 0000 "></property> </bean> -       <!--P-namespace notation <bean id= "car2" class= "cn.itcast.spring3.demo5.Car2" p:name= "BMW" p:price= "400000" > </b Ean> -       <!--spel notation -       <BeanID= "Car2"class= "Cn.itcast.spring3.demo5.Car2" >       < Propertyname= "Name"value= "#{' Public '}"></ Property>       < Propertyname= "Price"value= "#{' 120000 '}"></ Property>       </Bean>                            <!--<bean id= "person" class= "Cn.itcast.spring3.demo5.Person" > <property name= "Name" Val       Ue= "Ren Tong" ></property> <property name= "car2" ref= "Car2" ></property> </bean>  -              <!--the wording of the P namespace -       <!--<bean id= "person" class= "Cn.itcast.spring3.demo5.Person" p:name= "Tongtong" p:car2-ref= "Car2" > </bean&       Gt  -       <!--spel notation -       <BeanID= "Person"class= "Cn.itcast.spring3.demo5.Person">       <!--<property name= "name" value= "#{' small Side '}" ></property> -           <!--<property name= "name" value= "#{personinfo.name}" ></property> -           < Propertyname= "Name"value= "#{personinfo.showname ()}"></ Property>           < Propertyname= "Car2"value= "#{car2}"></ Property>                     </Bean>              <!--<property name= "name" value= "Ren Tong" ></property> <property name= "car2" ref= "C Ar2 "></property> -        <BeanID= "PersonInfo"class= "Cn.itcast.spring3.demo5.PersonInfo">        < Propertyname= "Name"value= "Zhang San"></ Property>            </Bean></Beans>
 PackageCn.itcast.spring3.demo5; Public classPersonInfo {PrivateString name;  Public voidSetName (String name) {//setting is set         This. Name =name; }     PublicString GetName () {//your property wants to get it in the config file and it must have get .        returnname; }     PublicString ShowName () {returnname; }}

day38 13-spring of the Bean's attributes: Spel injection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.