Spring基础(8) : properties配置文件

    <context:property-placeholder location="p.properties"/>

    <bean id="p" class="com.Person">
         <property name="name" value="${name}"/>
    </bean>

  

工程 resource下新建一个 p.properties文件,里面内容为:

name=hahadaxiao

  

使用:

public static void main(String[] args){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("a.xml");
        Person p = context.getBean("p",Person.class);
        System.out.println(p.name);
    }

  打印:

hahadaxiao

若有多个properties文件,则用 *号通配符,或者用逗号分隔

<context:property-placeholder location="*.properties"/>
<context:property-placeholder location="p.properties,pbp.properties"/>

  

原文地址:https://www.cnblogs.com/lh218/p/6551260.html