在 spring boot 中使用可变 wsdllocation 字段
在 spring boot 中的 @webserviceclient 注解中,wsdllocation 字段通常用于指定 wsdl 文件的地址。然而,在不同的环境(如测试和生产)中使用不同的地址是很常见的。本文将介绍如何将 wsdllocation 字段配置为变量,以便在不同的环境中使用不同的地址。
首先,创建一个类,用于从配置文件中读取 wsdllocation 值,并添加 @component 注解使其成为 spring bean:
@component("contextconfig") public class contextconfig { @value("${wsdllocation}") public string wsdllocation; }
接下来,在配置文件中指定 wsdllocation 值:
green_enterprise_server_ws_url: https://aquavn-tt78admindemo.vnpt-invoice.com.vn/publishservice.asmx?wsdl
在需要使用 wsdllocation 的地方,注入 contextconfig bean,并使用 wsdllocation 字段:
@resource(name = "contextconfig") contextconfig contextconfig; url wsdllocation = new url(contextconfig.wsdllocation);
这样,wsdllocation 字段就可以根据配置文件中的值进行修改,从而在不同的环境中使用不同的 wsdl 文件地址。需要注意的是,需要使用代码的方式创建 service 对象,并手动指定 wsdllocation 和 servicename 等参数:
URL wsdlLocation = new URL(contextConfig.wsdlLocation); QName serviceName = new QName("http://example.org/sample", "MyService"); Service service = Service.create(wsdlLocation, serviceName);
以上就是Spring Boot 中如何动态配置 @WebServiceClient 注解的 wsdlLocation 字段?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号