Spring Read configuration file

Source: Internet
Author: User

Description

Typically, the project will have the need to read the configuration file, which can be used for property files, XML files, and so on. Here, Spring uses the object feature to be read, and to write a sample of the property.

Demo two properties indicate items that are frequently used first, the map object of key, value relationship (similar property file), List object


Java objects

Package Eway.flight.utils;import Java.util.list;import Java.util.map;import org.springframework.stereotype.repository;/** * * @author YZP */@Repositorypublic 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.getva        Luemap (). 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; }    }

configuration file

<?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> <entr Y key= "mail_message_template" > <value> you have a new email! Sender: {from}; Send: {time}; Title: {title}. </value> </entry> <entry key= "schedule_module_id" > < value>68</value> </entry> <entry key= "Schedule_prompt_message_template"                    ; <value> your personal schedule reminder: {title} will start at {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 Read configuration file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.