At work, leaders think that the properties file is too disgusting (in fact, they don't want to use it). Fortunately, the properties file is a string problem, below is a list of common methods for instantiating string, file, map, and list objects in spring. For your reference. Let's talk about the code.
<? 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-2.0.xsd"> <! -- Solr_home: directly accesses solrresourceloader. locatesolrhome (); --> <bean id = "uesec.core.solr_home.txt" class = "Java. lang. string "Singleton =" true "> <constructor-Arg> <value>. \ puese_home \ </value> </constructor-Arg> </bean> <bean id = "uesec.core.solr_xml.txt" class = "Java. io. file "Singleton =" true "> <constructor-Arg Index =" 0 "> <ref bean =" uesec.core.solr_home.txt "/> </constructor-Arg> <constructor-Arg Index =" 1 "Type =" Java. Lang. String "> <value> SOLR. xml </value> </constructor-Arg> </bean> <! -- SOLR service: Kernel name --> <bean id = "uesec.core.solr_core.txt" class = "Java. lang. string "Singleton =" true "> <constructor-Arg type =" Java. lang. string "> <value> TXT </value> </constructor-Arg> </bean> <bean id =" uesec.core.solr_corecontainer.txt "class =" org. apache. SOLR. core. corecontainer "Singleton =" true "> <constructor-Arg Index =" 0 "type =" Java. lang. string "> <ref bean =" uesec.core.solr_home.txt "/> </constructor-Arg> <Constructor-Arg Index = "1" type = "Java. io. file "> <ref bean =" uesec.core.solr_xml.txt "/> </constructor-Arg> </bean> <! -- Construct list --> <bean id = "namelist" class = "Java. util. arraylist "> <constructor-Arg> <list> <value> liuyu </value> </List> </constructor-Arg> </bean> <! -- Construct map --> <bean id = "namemap" class = "Java. util. hashmap "> <constructor-Arg> <map> <Entry key =" liuyu "value-ref =" namelist "/> </map> </constructor-Arg> </Bean> <! -- Inject list and map --> <bean id = "mydemo" class = "Spring. inject. demo. mydemo "> <property name =" namelist "> <ref local =" namelist "/> </property> <property name =" namemap "> <ref local =" namemap "/> </property> </bean> </beans>
public class MyDemo { private List<String> nameList = null; private Map<String, List<String>> nameMap = null; public List<String> getNameList() { return nameList; } public void setNameList(List<String> nameList) { this.nameList = nameList; } public Map<String, List<String>> getNameMap() { return nameMap; } public void setNameMap(Map<String, List<String>> nameMap) { this.nameMap = nameMap; }}