码迷,mamicode.com
首页 > 编程语言 > 详细

Spring读取配置文件

时间:2015-12-10 21:25:53      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

说明:

通常情况下,项目将有读取配置文件的需求,可以用于property文件、xml文件等。这里使用spring该对象特征可被读取,写读属性样本。

demo两个属性表明经常使用的物品首先,key 、value关系的map对象(类似property文件)、列表对象list


java对象

package eway.flight.utils;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

/**
 *
 * @author yzp
 */
@Repository
public class SystemConfig {
    
    private Map valueMap;
    private List userids;
    

    public List getUserids() {
		return userids;
	}

	public void setUserids(List userids) {
		this.userids = userids;
	}

	public Map getValueMap() {
        return valueMap;
    }

    public void setValueMap(Map valueMap) {
        this.valueMap = valueMap;
    }
    
    public Object getValue(String key){
        if (this.getValueMap().containsKey(key)){
            return this.getValueMap().get(key);
        }else{
            return "";
        }
    }
    
    private List searchConfigList;

    public List getSearchConfigList() {
        return searchConfigList;
    }

    public void setSearchConfigList(List searchConfigList) {
        this.searchConfigList = searchConfigList;
    }

    private Map sendRangeConfig;

    public Map getSendRangeConfig() {
        return sendRangeConfig;
    }

    public void setSendRangeConfig(Map sendRangeConfig) {
        this.sendRangeConfig = sendRangeConfig;
    }
            
    private List syncUserConfigList;

    public List getSyncUserConfigList() {
        return syncUserConfigList;
    }

    public void setSyncUserConfigList(List syncUserConfigList) {
        this.syncUserConfigList = syncUserConfigList;
    }
    
}

配置文件

<?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-3.0.xsd
">
    <bean id="SystemConfig" class="eway.flight.utils.SystemConfig">
        <property name="valueMap">
            <map>
                <entry key="mail_message_template">
                    <value>您有一封新邮件!发信人:{from};发送时间:{time};标题:{title}。</value>
                </entry>
                <entry key="schedule_module_id">
                    <value>68</value>
                </entry>
                <entry key="schedule_prompt_message_template">
                    <value>您的个人日程提醒 : {title} 将在 {time} 開始!。</value>
                </entry>
                <entry key="pm25_import_file_path">
                    <value>c:\pm25.txt</value>
                </entry>
            </map>
        </property>
        <property name="userids">
			<bean class="org.springframework.beans.factory.config.ListFactoryBean">
				<property name="targetListClass">
					<value>java.util.ArrayList</value>
				</property>
				<property name="sourceList">
					<list>
						<value>usr1</value>
						<value>usr2</value>
						<value>usr3</value>
					</list>
				</property>
			</bean>
		</property>      
    </bean>
</beans>




Spring读取配置文件

标签:

原文地址:http://www.cnblogs.com/yxwkf/p/5037233.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!