java读取xml配置参数代码实例

作者:明天会更好啊 时间:2023-11-25 03:03:17 

这篇文章主要介绍了java读取xml配置参数代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

paras.xml文件


<?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-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">

<bean id="SysParam" class="com.wisoft.tysfrz.utils.SysParam">
 <!--行政区划代码前台显示默认值-->
 <property name="zoneCode" value="36"></property>
 <!--二代证读卡器读取照片存储位置-->
 <property name="sfzpicpath" value="d:\\"></property>
 <!--保存身份证照片相对路径-->
 <property name="photoRealPath" value="r/project/imgs/photo/"></property>
</bean>
</beans>

SysParam.java类文件


package com.wisoft.tysfrz.utils;
/**
* 系统配置参数
*
* @author ZHENWENCAN
* @date 2017年10月9日 下午1:09:48
*/
public class SysParam {
//行政区划代码前台显示默认值
private String zoneCode;
//二代证读卡器读取照片存储位置
private String sfzpicpath;
//保存身份证照片相对路径
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;
}
}

使用


private static ApplicationContext cpxac = new ClassPathXmlApplicationContext("tysfrz/spring/tysfrz_params.xml");
private static SysParam sysparam = (SysParam) cpxac.getBean("SysParam");

String photorealpath = sysparam.getPhotoRealPath();

需要引用包


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

来源:https://www.cnblogs.com/txdah/p/12094073.html

标签:java,读取,xml,配置,参数
0
投稿

猜你喜欢

  • 关于@ConditionalOnProperty的作用及用法说明

    2023-11-24 02:39:19
  • java 动态 代理的方法总结

    2023-08-25 04:00:33
  • jar命令的用法详解

    2022-08-14 13:37:28
  • C#实现的字符串相似度对比类

    2023-08-08 20:35:10
  • android在连拍菜单中增加连拍张数选项功能实现代码

    2023-05-27 19:08:38
  • 为什么不建议使用Java自定义Object作为HashMap的key

    2021-09-21 06:15:05
  • C#获取打印机列表方法介绍

    2022-07-29 02:54:38
  • SpringBoot 项目的创建与启动步骤详解

    2022-01-23 16:51:17
  • Android之listfragment的使用例子

    2021-05-31 02:10:19
  • 基于WPF实现验证码控件

    2021-08-15 21:44:36
  • Eclipse下编写java程序突然不会自动生成R.java文件和包的解决办法

    2023-11-19 00:24:05
  • 通过FeignClient调用微服务提供的分页对象IPage报错的解决

    2022-01-27 20:19:23
  • Java集合框架Collections原理及用法实例

    2021-12-04 18:10:20
  • Android使用多线程进行网络聊天室通信

    2022-05-11 18:56:36
  • Java中常用时间的一些相关方法

    2022-02-06 11:33:38
  • java静态工具类注入service出现NullPointerException异常处理

    2021-11-28 09:59:11
  • Android开发实现读取Assets下文件及文件写入存储卡的方法

    2023-02-07 15:42:21
  • springboot整合security和vue的实践

    2021-09-17 20:39:28
  • Spring框架中一个有用的小组件之Spring Retry组件详解

    2021-05-27 10:07:40
  • Android线程间通信Handler源码详解

    2021-12-31 07:04:10
  • asp之家 软件编程 m.aspxhome.com