spring中xml配置文件

2021-05-09 07:30

阅读:714

标签:day   singleton   get   工厂   static   其他属性   cfa   无法   service   

1.Bean

技术图片技术图片
xml version="1.0" encoding="UTF-8"?>
beans xmlns="http://www.springframework.org/schema/beans"
       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">

    
    

    
    

    

    

    

    
    bean id="accountService" class="com.itheima.service.impl.AccountServiceImpl"
          scope="prototype" init-method="init" destroy-method="destroy">bean>
beans>
View Code

2.DI(依赖注入)

技术图片技术图片
xml version="1.0" encoding="UTF-8"?>
beans xmlns="http://www.springframework.org/schema/beans"
       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">

    


    
    bean id="accountService" class="com.itheima.service.impl.AccountServiceImpl">
        constructor-arg name="name" value="泰斯特">constructor-arg>
        constructor-arg name="age" value="18">constructor-arg>
        constructor-arg name="birthday" ref="now">constructor-arg>
    bean>

    
    bean id="now" class="java.util.Date">bean>



    
    bean id="accountService2" class="com.itheima.service.impl.AccountServiceImpl2">
        property name="name" value="TEST" >property>
        property name="age" value="21">property>
        property name="birthday" ref="now">property>
    bean>


    
    bean id="accountService3" class="com.itheima.service.impl.AccountServiceImpl3">
        property name="myStrs">
            set>
                value>AAAvalue>
                value>BBBvalue>
                value>CCCvalue>
            set>
        property>

        property name="myList">
            array>
                value>AAAvalue>
                value>BBBvalue>
                value>CCCvalue>
            array>
        property>

        property name="mySet">
            list>
                value>AAAvalue>
                value>BBBvalue>
                value>CCCvalue>
            list>
        property>

        property name="myMap">
            props>
                prop key="testC">cccprop>
                prop key="testD">dddprop>
            props>
        property>

        property name="myProps">
            map>
                entry key="testA" value="aaa">entry>
                entry key="testB">
                    value>BBBvalue>
                entry>
            map>
        property>
    bean>











beans>
View Code

 

spring中xml配置文件

标签:day   singleton   get   工厂   static   其他属性   cfa   无法   service   

原文地址:https://www.cnblogs.com/jingpeng77/p/13174448.html


评论


亲,登录后才可以留言!