I have .wsdl file which I want to Environmentalize. For each environment it will be same, only different will be in address location property. Exist any way how to set this value dynamically from application.yaml file?
<wsdl:service name="PaymentService">
<wsdl:port name="PaymentPortV1" binding="ns:PaymentServiceSoap">
<wsdlsoap:address location="${gpwebpay.location}"/>
</wsdl:port>
</wsdl:service>
A possible solution is to use Maven Profiles in tandem with Maven Resources Plugin.
<profiles>
<profile>
<id>profile1</id>
<properties>
<gpwebpay.location>https://default.location.com/</gpwebpay.location>
</properties>
</profile>
<profile>
<id>profile2</id>
<properties>
<gpwebpay.location>https://other.location.com/</gpwebpay.location>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>filter-resources</id>
<phase>package</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/resources/wsdl</directory>
<filtering>true</filtering>
<includes>
<include>**/*.wsdl</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<build>
Depending on your environment:
mvn -Pprofile1 clean install
or:
mvn -Profile2 clean install
Will end up with your desired WSDL file in target/classes/sample.wsdl
:
<wsdl:service name="PaymentService">
<wsdl:port name="PaymentPortV1" binding="ns:PaymentServiceSoap">
<wsdlsoap:address location="https://other.location.com/"/>
</wsdl:port>
</wsdl:service>
In this case I specified -Pprofile2
.
IMPORTANT: With Spring Framework / Spring Boot, you should use @notation@
for your variables:
<wsdl:service name="PaymentService">
<wsdl:port name="PaymentPortV1" binding="ns:PaymentServiceSoap">
<wsdlsoap:address location="@gpwebpay.location@"/>
</wsdl:port>
</wsdl:service>
If you're already using Spring Profiles in your project, I would suggest to create a profile like this:
<profile>
<id>test</id>
<properties>
<spring.profiles.active>test</spring.profiles.active>
<filter.filename>src/main/resources/application-test.properties</filter.filename>
</properties>
</profile>
Next, use the defined filter.filename
property in the plugin:
<configuration>
<filters>
<filter>${filter.filename}</filter>
</filters>
</configuration>
Invoke Maven:
mvn -Ptest clean install