Read the configuration parameters in the xml file and the parameters in the xml file.
Paras. xml 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" xmlns: aop = "http://www.springframework.org/schema/aop" xmlns: tx = "http://www.springframework.org/schema/tx" xmlns: context = "http://www.springframework.org/schema/context" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-bean S-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd> <bean id = "SysParam" class = "com. wisoft. tysfrz. utils. SysParam"> <! -- Default value displayed on the front-end of the Administrative Division code --> <property name = "zoneCode" value = "36"> </property> <! -- The location where the secondary card reader reads the photos --> <property name = "sfzpicpath" value = "d :\\"> </property> <! -- Save the relative path of the ID card photo --> <property name = "photoRealPath" value = "r/project/imgs/photo/"> </property> </bean> </beans>
SysParam. java files
Package com. wisoft. tysfrz. utils;/*** system configuration parameters ** @ author ZHENWENCAN * @ date 1:09:48 on January 1, October 9, 2017 */public class SysParam {// display the default private String zoneCode on the front-end of the Administrative Division code; // private String sfzpicpath; // The relative path of the ID card photo to be read; // The private String photoRealPath; public String getZoneCode () {return zoneCode;} public void setZoneCode (String zoneCode) {this. zoneCode = zoneCode;} public String getSfzpicpath () {return sfzpicpath;} public void setSfzpicpath (String sfzpicpath) {this. sfzpicpath = sfzpicpath;} public String getPhotoRealPath () {return photoRealPath;} public void setPhotoRealPath (String photoRealPath) {this. photoRealPath = photoRealPath ;}}
Use
Private static ApplicationContext cpxac = new ClassPathXmlApplicationContext ("tysfrz/spring/tysfrz_params.xml ");
Private static SysParam sysparam = (SysParam) cpxac. getBean ("SysParam ");
String photorealpath = sysparam. getPhotoRealPath ();
Package to be referenced
Import org. springframework. context. ApplicationContext;
Import org. springframework. context. support. ClassPathXmlApplicationContext;