【问题标题】:Deploying Spring Boot App in Wildfly 9.0.2在 Wildfly 9.0.2 中部署 Spring Boot 应用程序
【发布时间】:2018-02-12 20:31:45
【问题描述】:

我想将一个简单的 Spring Boot Rest 应用程序部署到 Wildfly 9.0.2 服务器中。它似乎已部署但无法访问任何服务。

我一直在遵循各种指示,例如: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html

但似乎仍然不适合我。

这是我的 pom.xml 文件

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.vodafone.er</groupId>
<artifactId>config-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>config-app</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
    <relativePath/>
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <start-class>com.vodafone.er.configapp.ConfigAppApplication</start-class>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
            </exclusion>
        </exclusions>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.module</groupId>
        <artifactId>jackson-module-parameter-names</artifactId>
        <version>2.8.7</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jdk8</artifactId>
        <version>2.8.7</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jsr310</artifactId>
        <version>2.8.7</version>
    </dependency>
</dependencies>

<!--<build>-->
    <!--<plugins>-->
        <!--<plugin>-->
            <!--<groupId>org.springframework.boot</groupId>-->
            <!--<artifactId>spring-boot-maven-plugin</artifactId>-->
            <!--<configuration>-->
                <!--<jvmArguments>-->
                    <!-- -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005-->
                <!--</jvmArguments>-->
            <!--</configuration>-->
        <!--</plugin>-->
    <!--</plugins>-->
<!--</build>-->

这是我的应用程序/控制器类:

@SpringBootApplication
@ComponentScan
@EnableAutoConfiguration
public class ConfigAppApplication extends     
    SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(ConfigAppApplication.class, args);
    }

    @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(ConfigAppApplication.class);
        }
    }

    @RestController
    class ConfigController {

    @RequestMapping("/hello")
    public String hello() {
        return "hello world";
    }
}

我将它部署在 $JBOSS_HOME/standalone/deployments 上,它告诉我它已部署。

15:51:12,008 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0016: Replaced deployment "config-app-0.0.1-SNAPSHOT.war" with deployment "config-app-0.0.1-SNAPSHOT.war"

我得到了标记文件:

config-app-0.0.1-SNAPSHOT.war.deployed

jmx 控制台告诉我应用程序也已启用。 每当我尝试访问端点时,例如当我尝试访问根上下文时,我得到了 403 禁止,但是当我尝试访问其余资源时,例如localhost:8080/config-app/hello 我收到 404 错误。

任何想法我做错了什么?

谢谢

【问题讨论】:

  • 这就是ConfigAppApplication 的全部来源吗?它缺少 @SpringBootApplication 或等效的单独注释。
  • 在应用服务器上部署独立应用没有任何意义。
  • @AndyWilkinson - 我已经编辑了这个问题。我想我是不小心把它删除了,所以谢谢你的提醒。
  • @KarlNicholas - 问题不在于它是否有意义。这是一个测试,看看它是否在这个版本的 Wildfly 中工作,然后我将它集成到现有的 Wildfly 中,其中包含多个 Web 应用程序。例如,我可以使用嵌入式 Tomcat/Jetty 轻松使用它,但是按照我提到的示例,我无法使用其余服务。我一定是做错了什么?
  • 我有点困惑,为什么你的 pom 专门排除了 tomcat 依赖,然后又明确地包含它。这似乎是剧烈随机测试的结果(注释掉的构建部分进一步证明了这一点),而不是我们检查的合适的干净 pom。

标签: spring-boot wildfly


【解决方案1】:

Wildfly 使用 undertow servlet 容器。尝试在您的应用程序中添加对它的支持。

参考:73.13 Use Undertow instead of Tomcat

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

【讨论】:

  • 我可以试一试,但是 Wildfly 提供了 Undertow ...所以我想在运行时使用该 Undertow 服务器 - 而不是 Spring Boot 依赖项。
  • 阅读文档,我想他们说 springboot-undertow 只是附加到 undertow 容器上。我认为这对于 springboot servlet 容器库来说可能是正确的。
  • 这是我在其他地方没见过的非常有价值的信息^
【解决方案2】:
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
</dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-10
    • 1970-01-01
    • 2018-10-20
    • 2017-08-26
    • 2020-09-11
    • 2017-09-30
    • 1970-01-01
    • 2019-06-07
    相关资源
    最近更新 更多