更改Wildfly上部署的春季项目的港口

发布于 2025-02-09 06:23:54 字数 1867 浏览 2 评论 0原文

主持人注意:其他现有问题,请参考默认接口。我对改变这一点不感兴趣。我需要专门更改每个部署的端口。

其他问题是在独立模式下运行的野生蝇。我正在作为Windows Server服务运行。

基于此,请不要解决问题。

现在,问题:

作为参考以下春季应用程序,在Windows Server 2019上以服务为服务的Wildfly运行:

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


}

当我使用Tomcat时,更改Web服务端口很容易添加:

application.properties

server.port = 8093

导致所需的URL:

http://127.0.0.1:8093/swagger-ui.html

但是,在Wildfly上部署被证明更难。首先,它是.war名称和错误的上下文根,我通过添加以下更改来修复:

pom.xml

<finalName>${project.artifactId}</finalName>

src \ main \ main \ webapp \ 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>

但是,这是最后一个问题。 Web服务正在 而不是使用端口8093。

如何更改Wildfly中每个部署的Web服务的端口,而不是默认的8080?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

围归者 2025-02-16 06:23:54

server.port属性仅控制Spring Boot应用程序中嵌入式服务器的侦听端口(Tomcat,Jetty等)。

在部署期间指定了独立应用程序服务器中的应用程序端口。在Wildfly上执行此操作的最简单方法是通过wildfly-maven-plugin

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文