读取xml文件中的配置参数实例

  

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt;豆类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:上下文=" http://www.springframework.org/schema/context "   xsi: schemaLocation="   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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”比;         & lt; bean id=癝ysParam”类=癱om.wisoft.tysfrz.utils.SysParam”比;   & lt; !——行政区划代码前台显示默认值——比;   & lt;属性名=" zoneCode " value=" https://www.yisu.com/zixun/36 "祝辞& lt;/property>   & lt; !——二代证读卡器读取照片存储位置——比;   & lt;属性名=" sfzpicpath " value=" d: \ \ "祝辞& lt;/property>   & lt; !——保存身份证照片相对路径——比;   & lt;属性名=" photoRealPath " value=" https://www.yisu.com/zixun/r/project/imgs/photo/"祝辞& lt;/property>   & lt;/bean>   & lt;/beans>      

        包com.wisoft.tysfrz.utils;/* *   *系统配置参数   *   * @author ZHENWENCAN   * @date 2017年10月9日下午1:09:48   */公开课SysParam {//行政区划代码前台显示默认值   私人字符串zoneCode;//二代证读卡器读取照片存储位置   私人字符串sfzpicpath;//保存身份证照片相对路径   私人字符串photoRealPath;   公共字符串getZoneCode () {   返回zoneCode;   }   公共空间setZoneCode(字符串zoneCode) {   这一点。zoneCode=zoneCode;   }   公共字符串getSfzpicpath () {   返回sfzpicpath;   }   公共空间setSfzpicpath(字符串sfzpicpath) {   这一点。sfzpicpath=sfzpicpath;   }   公共字符串getPhotoRealPath () {   返回photoRealPath;   }   公共空间setPhotoRealPath(字符串photoRealPath) {   这一点。photoRealPath=photoRealPath;   }   }      

<强>使用

        私有静态ApplicationContext cpxac=new ClassPathXmlApplicationContext (“tysfrz/spring/tysfrz_params.xml”);   私有静态SysParam SysParam=(SysParam) cpxac.getBean (“SysParam”);      字符串photorealpath=sysparam.getPhotoRealPath ();      之前      

<强>需要引用包

        进口org.springframework.context.ApplicationContext;   进口org.springframework.context.support.ClassPathXmlApplicationContext;      之前      

以上这篇读取xml文件中的配置参数实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

读取xml文件中的配置参数实例