Java read XML configuration parameter code instance

Time:2021-2-12

This article mainly introduces the example of Java reading XML configuration parameter code. The example code is introduced in great detail, which has a certain reference learning value for everyone’s study or work. If you need a friend, you can refer to it

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-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>
  <! -- default value of administrative division code displayed in foreground -- >
  <property name="zoneCode" value="36"></property>
  <! -- the second generation card reader reads the photo storage location -- >
  <property name="sfzpicpath" value="d:\\"></property>
  <! -- relative path to save ID card photo -- >
  <property name="photoRealPath" value="r/project/imgs/photo/"></property>
 </bean>
</beans>

SysParam.java Class file

package com.wisoft.tysfrz.utils;
/**
 *System configuration parameters
 * 
 * @author ZHENWENCAN
 *@ date October 9, 2017 1:09:48 PM
 */
public class SysParam {
 //The default value of administrative division code is displayed in the foreground
 private String zoneCode;
 //Second generation card reader reads photo storage location
 private String sfzpicpath;
 //Save relative path of ID card photo
 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();

Reference package required


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

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.

Recommended Today

CSS uses position + margin to realize the horizontal and vertical centering of fixed boxes

margin:auto; + position: absolute; Up, down, left and right: 0Just look at the demo <!DOCTYPE html> <html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″> <meta charset=”utf-8″> <meta name=”viewport” content=”initial-scale=1.0, maximum-scale=1.0, user-scalable=no” /> < title > use position + margin to center the fixed box horizontally and vertically < / Title > <style> body * { outline: 1px […]