zoukankan      html  css  js  c++  java
  • Spring读取配置文件

    说明:

    通常情况下,项目将有读取配置文件的需求,可以用于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>
    




  • 相关阅读:
    AI boxfilter
    AI AdaBoost算法
    AI Haar特征
    15.VUE学习之-表单中使用key唯一令牌解决表单值混乱问题
    14.VUE学习之-v-if v-else-if语法在网站注册中的实际应用讲解
    13.VUE学习之控制行内样式
    12.2 VUE学习之-if判断,实践加减input里的值
    12.1.VUE学习之-循环li,if判断示例讲解class中应用表达式
    10.VUE学习之使用lodash库减少watch对后台请求的压力
    09.VUE学习之watch监听属性变化实现类百度搜索栏功能ajax异步请求数据,返回字符串
  • 原文地址:https://www.cnblogs.com/yxwkf/p/5037233.html
Copyright © 2011-2022 走看看