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;
}
}