@WebServiceClient wsdlLocation 动态给注解内容参数赋值,解决static静态代码块赋值注入,从配置文件读取内容动态给注解里参数赋值

static静态代码块优先于类加载,这时候如果你要读取配置文件并注入到注解里,实现根据配置文件动态获取,就有问题了。
如果某些环境,可以参考使用继承父类方式
父类普通代码块加载配置文件,这里用父类的属性给自己赋值即可
Father.WSDLURL

@WebServiceClient(name = "mmsService",
        wsdlLocation = "${WSDLURL}",
        targetNamespace = "hjhz")
public class MmsService extends Service {

	//静态变量在静态代码块加载后加载,且注解也在之后加载,完成动态注入修改注解里的参数
    public static String WSDLURL;
    public final static URL WSDL_LOCATION;

    public final static QName SERVICE = new QName("hjhz", "mmsService");
    public final static QName MmsServiceHttpPort = new QName("hjhz", "mmsServiceHttpPort");

    static {
        Properties properties = new Properties();
        try {
            properties = PropertiesLoaderUtils.loadAllProperties("配置文件名例如:bootstrap.yml");
            //遍历取值  
            Set<Object> objects = properties.keySet();
            for (Object object : objects) {
            //取到参数赋值给静态变量
                if (object.toString().equals("WSDLURL")) {
                    System.out.println(new String(properties.getProperty((String) object).getBytes("iso-8859-1"), "gbk"));
                    WSDLURL = new String(properties.getProperty((String) object).getBytes("iso-8859-1"), "gbk");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        URL url = null;
        try {
            url = new URL(WSDLURL);
        } catch (MalformedURLException e) {
            java.util.logging.Logger.getLogger(MmsService.class.getName())
                    .log(java.util.logging.Level.INFO,
                            "Can not initialize the default wsdl from {0}", WSDLURL);
        }
        WSDL_LOCATION = url;
    }
  • 7
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值