2.spring引入外部属性文件

1.外部文件的config.properties
    username=wmd----------------------------->此处需要注意的是:(username是spring的关键字,命名时需要避开,不要使用username)
    age=24
2.spring配置文件路径
    2.1
        <?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:p="http://www.springframework.org/schema/p"
               xmlns:util="http://www.springframework.org/schema/util"
               xmlns:context="http://www.springframework.org/schema/context"---------------->需要加入这一行
               xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd------------->也必须加入这一行,不然会报错:(通配符的匹配很全面, 但无法找到元素 ')
                ">)_
    2.2
    <context:property-placeholder location="classpath:conf/config.properties"/>-------->引入外部的属性文件:classpath意思是在类路径下加载
    <bean id="person" class="entity.Person">
        <property name="name" value="${username}"></property>
        <property name="age" value="${age}"></property>
    </bean>

 

posted @ 2022-05-05 22:27  努力的达子  阅读(107)  评论(0编辑  收藏  举报