【问题标题】:Unable to deploy Spring Boot application in Wildfly 8 AS无法在 Wildfly 8 AS 中部署 Spring Boot 应用程序
【发布时间】:2018-10-20 17:37:14
【问题描述】:

我是 Spring Boot 新手,在将 Spring Boot 应用程序部署到 Wildfly 8 服务器时遇到问题。我按照互联网上的一些链接将 Spring Boot 应用程序部署为 war 文件,但没有工作。

我的 pom.xml 文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.13.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.7</java.version>
    </properties>

    <dependencies>
        <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-test</artifactId>
            <scope>test</scope>
        </dependency>
         <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <scope>provided</scope>
        </dependency>
    </dependencies>

</project>

我的入门课程如下:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer  {

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

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

我已经公开了一个 Rest 方法,Rest Controller 如下所示:

package com.example.demo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

    @RestController
    @RequestMapping("/hello")
    public class HelloController {
        @RequestMapping("/sayHello")
        public String sayHello( ) {
            return "hello";
        }
    }

我的项目在嵌入式 tomcat 中运行,但不在 Wildfly 服务器中。请帮忙。

【问题讨论】:

  • 请显示控制台错误
  • 当我在服务器中部署并点击 http://>:>/hello/sayHello,URL 没有被点击。没有错误,但无法访问
  • 您同时使用了 Tomcat 和 Wildfly 8 服务器,首先删除 pom.xml 文件中的 tomcat 依赖项,然后正常工作。我希望@Anirban
  • 在我的 pom.xml 中,我已经排除了带有工件 id spring-boot-starter-tomcat 的 tomcat 依赖
  • 我还需要做什么?

标签: java spring-boot wildfly


【解决方案1】:

如果您在部署应用程序时没有遇到任何异常,请尝试通过点击以下 URL 访问该应用程序并检查它是否有效:
http://:/name_of_your_war/hello/sayHello

【讨论】:

    猜你喜欢
    • 2017-08-26
    • 2018-02-12
    • 2020-07-10
    • 1970-01-01
    • 2019-06-07
    • 2015-10-03
    • 1970-01-01
    • 2020-09-11
    • 2020-04-13
    相关资源
    最近更新 更多