Use spring to replace the properties file to define Properties

Source: Internet
Author: User
Tags solr

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; }}

 

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.