Note to moderator: Other existing questions in SO make reference to the default interface. I'm not interested on changing that. I need to specifically change the port of each deployment.
Other questions regard wildfly running in standalone mode. I'm running it as a Windows Server Service.
Based on this please do not close the question.
Now, the question:
Taking as a reference the following Spring application, running on Wildfly on Windows Server 2019 installed as a service:
@Configuration
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
static Logger logger = LoggerFactory.getLogger(DemoApplication.class);
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
private static Class<DemoApplication> applicationClass = DemoApplication.class;
}
When I was using Tomcat, changing the web service port was easy as adding:
Application.properties
server.port=8093
Resulting in the desired URL:
http://127.0.0.1:8093/swagger-ui.html
However, deploying on Wildfly proved to be harder. At first, it was the .war name and the wrong context root, which I fixed by adding the following changes:
pom.xml
<finalName>${project.artifactId}</finalName>
src\main\webapp\WEB-INF\jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<context-root>/</context-root>
</jboss-web>
However, there's the last problem. The web service is being exposed on http://127.0.0.1:8080/swagger-ui.html instead of using port 8093.
How can I change the port of each deployed web service in Wildfly, instead of the default 8080?
The server.port
property only controls the listening port of an embedded server in a Spring boot app (tomcat, jetty, etc.).
The app's port in a standalone application server is specified during the deployment. The easiest way to do this on Wildfly is via the wildfly-maven-plugin
(https://docs.jboss.org/wildfly/plugins/maven/latest/deploy-mojo.html):
<build>
<plugins>
<!-- ... -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.1.0.Final</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<filename>${project.build.finalName}.war</filename>
<hostname>127.0.0.1</hostname>
<port>8093</port> <!-- <<<<<<<< -->
<username>my-wildfly-user</username>
<password>my-wildfly-password</password>
</configuration>
</plugin>
<!-- ... -->
</plugins>
</build>