Sprint加载properties文件内容相关配置。

来源:互联网 发布:网络遭遇撞库攻击 编辑:程序博客网 时间:2024/05/16 14:32

properties文件路径:config/properties/test.properties

内容:

test.id=123

test.name=测试


XML配置文件:

<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>config/properties/test.properties</value><!-- 加载队列配置文档 -->
</list>
</property>
</bean>

<bean class="com.test.entity.Test">

<property name="id" >
  <value>${test.id}</value>
</property>

<property name="name" >
  <value>${test.name}</value>
</property>

</bean>


Test类:

public class Test{

public static String id;

public static String name;

//get set方法...

}

0 0
原创粉丝点击