spring day2-配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">

    <!-- 引用的方式注入集合类型的值 -->
    <util:list id='citiesBean'>
        <value>北京</value>
        <value>上海</value>
        <value>长沙</value>
    </util:list>

    <util:set id="interestBean">
        <value>钓鱼</value>
        <value>做饭</value>
        <value>台球</value>
    </util:set>
    
    <util:map id="scoreBean">
        <entry key="english" value="100" />
        <entry key="math" value="90" />
    </util:map>
    
    <util:properties id="dbBean">
        <prop key="user">tom</prop>
        <prop key="password">1234</prop>
    </util:properties>

    <bean id="msg" class="ioc.MessageBean">
        <property name="cities" ref="citiesBean" />
        <property name="interest" ref="interestBean"/>
        <property name="score" ref="scoreBean"></property>
        <property name="db" ref="dbBean"></property>
        <property name="name" value="Ward"></property>
    </bean>
    <!-- 读取properties文件的内容 让spring容器读取指定位置的properties内容
    存放到properties对象中, 
    classpath:内部的约定,根据classpath找-->
    <util:properties id="config" location="classpath:config.properties"/>
    
    <!-- Spring表达式来访问其他的bean属性 -->
    <bean id="eb" class="ioc.ExampleBean">
    <property name="ename" value="#{msg.name}"></property>
    <property name="city" value="#{msg.cities[1]}"></property>
    
    <!-- 下面读取math的分数也可以不写成msg.score.math
    把配置文件的内容已经读到bean里面了,通过util:map id="scoreBean 的id也可以读取-->
    <property name="score" value="#{scoreBean.math}"></property>
    <property name="pageSize" value="#{config.pageSize}"></property>    
    </bean>
    
</beans>  

 

-------------------------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">

        <!-- 配置组件扫描 ;指定包annotation才会扫描-->
        <context:component-scan base-package="annotation"/>
        
        <!-- 读取指定路径下面的properties文件内容 -->
        <util:properties id="config" location="classpath:config.properties"/>
        
        
</beans>  

 

----------------------------------------------------------------

config.properties

pageSize=10

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值