解析.properties

本文介绍了一个用于从属性文件中读取WSDL URL的Java实用工具类。该类使用Spring框架来定位属性文件的位置,并提供了获取特定键对应的值的方法。如果属性文件中未找到指定的键,则返回默认的本地主机地址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

wsdl_ip.properties:

person=http://localhost:8080/CXF_3/cxf/person?wsdl

---------------------------------------------------------------------

IpPortUtils.java

package cn.itcast.cxf.service.utils;

import java.io.InputStream;
import java.util.Properties;

import org.apache.cxf.common.util.StringUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class IpPortUtils {
	
	public static String getIpPort(String key) {
		try {
			Resource  resource = new ClassPathResource("cn/itcast/cxf/service/wsdl_ip.properties");
			InputStream inputStream = resource.getInputStream();
			Properties p = new Properties();
			p.load(inputStream);
			String ip = p.getProperty(key);
			System.out.println("get WSDL("+key+") ip:[" + ip +"]");
			return StringUtils.isEmpty(ip) ? "http://localhost:80" : ip;
		} catch (Exception e) {
			e.printStackTrace();
			return "http://localhost:80";
		}
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值