我在 src / wsdl 下有wsdl文件,我想知道是否可以从这个wsdl文件中的属性文件中读取值,如下所示:
<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3-b02-. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3-b02-. --><definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://AXLInterface.jaxws.AllInOne.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://AXLInterface.jaxws.AllInOne.org/" name="AXLInterfaceService">
<types>
<xsd:schema>
<xsd:import namespace="http://AXLInterface.jaxws.AllInOne.org/" schemaLocation="${wsdl.url}/AXLInterface?xsd=1"></xsd:import>
</xsd:schema>
</definitions>
我在applicationContext中定义 PropertyPlaceholderConfigurer ,如下所示:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:messages/application.properties</value>
<value>file:${APP_HOME}/Common/Conf/app.properties
</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true" />
<property name="searchSystemEnvironment" value="true" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
</bean>
当我尝试编译应用程序时,我在wsdl文件中出错:
[ERROR] Unable to parse "${wsdl.url}/AXLInterface?xsd=1" : Illegal character in path at index 1: ${wsdl.url}/AXLInterface?xsd=1
[ERROR] java.net.URISyntaxException: Illegal character in path at index 1: ${wsdl.url}/AXLInterface?xsd=1
请告知如何实现这一目标,谢谢。
答案 0 :(得分:3)
只需将WSDL文件定义为资源,这样Maven就可以了解它。但属性值应该在Maven配置文件中,而不是在属性文件中。
<resource>
<directory>src/wsdl</directory>
<filtering>true</filtering>
</resource>
答案 1 :(得分:0)
这假设您正在使用MessageDispatchServlet。
在您的web.xml中使用以下内容。这里的重要部分是transformWsdlLocation和wsdlDefinitionHandlerAdapterBeanName。最近,TransformWsdlLocation作为spring ws 2.1.2的一部分进行了更改,以修改schemaLocation。 https://jira.springsource.org/browse/SWS-791
<servlet>
<servlet-name>spring-ws</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>wsdlDefinitionHandlerAdapterBeanName</param-name>
<param-value>myWsdlDefinitionHandlerAdapter</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
接下来在spring-ws-servlet.xml配置文件中命名一个名为myWsdlDefinitionHandlerAdapter的bean。您可以从属性文件中获取的值,或者您需要从中获取的值。
接下来是扩展spring WsdlDefinitionHandlerAdapter的类MyWsdlDefinitionHandlerAdapter。在我的示例中,我通过修改服务器位置来更改wsdl位置。
public class MyWsdlDefinitionHandlerAdapter extends WsdlDefinitionHandlerAdapter {
private String serverAlias;
@Override
protected String transformLocation(String location, HttpServletRequest request) {
if(StringUtils.hasText(getServerAlias())){
StringBuilder url = new StringBuilder(request.getScheme());
url.append("://").append(getServerAlias());
if (location.startsWith("/")) {
// a relative path, prepend the context path
url.append(request.getContextPath()).append(location);
return url.toString();
}
else {
int idx = location.indexOf("://");
if (idx != -1) {
// a full url
idx = location.indexOf('/', idx + 3);
if (idx != -1) {
String path = location.substring(idx);
url.append(path);
return url.toString();
}
}
}
} else {
return super.transformLocation(location, request);
}
// unknown location, return the original
return location;
}
public String getServerAlias() {
return serverAlias;
}
public void setServerAlias(String serverAlias) {
this.serverAlias = serverAlias;
}
}
希望这有帮助。
答案 2 :(得分:0)
您必须为war插件启用过滤功能:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webResources>
<resource>
<directory>src/wsdl</directory>
<filtering>true</filtering>
</resource>
</webResources>
...
之后您可能需要更新您的maven项目配置。