【问题标题】:Springboot REST API returning 404 when deployed in Jboss EAP.7.1.0Springboot REST API 在 Jboss EAP.7.1.0 中部署时返回 404
【发布时间】:2021-09-20 08:15:38
【问题描述】:

我创建了一个简单的 Springboot REST api,它在部署在 Tomacat 容器中时工作正常,但在部署在 Jboss EAP 7.1.0 中时返回 404 消息。需要帮助来解决这个问题。

以下是我与 pom.xml 和 application.properties 一起编写的类

SpringRestApiApplication.java

package com.test.spring;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringRestApiApplication{

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

}

RestExample.java

package com.test.spring.web.controller;

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

@RestController
@RequestMapping(value = "/test")
public class RestExample {
    
    @GetMapping(value = "/hello")
    public String HelloWorldAPI() {
        return "Hello World!";
        
    }

}

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>       
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <groupId>com.example</groupId>
    <artifactId>SpringRestAPI</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>SpringRestAPI</name>
    <description>Rest API Test Example</description>
    
    <properties>
        <java.version>1.8</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>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        
        <dependency>
              <groupId>javax.servlet</groupId>
              <artifactId>javax.servlet-api</artifactId>              
              <scope>provided</scope>
        </dependency>
            
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>        
    </dependencies>

    <build>
        <finalName>rest-api</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

application.properties

server.servlet-path=/*

【问题讨论】:

  • 您的应用程序中有扩展SpringBootServletInitializer 的类吗?
  • @AndyWilkinson,在将 Spring Boot 版本更改为 2.1.5.RELEASE 并使用 SprringBootServletInitializer 扩展我的主类(SpringRestApiApplication)后,我能够达到终点(.../rest-api /test/hello) 仅当我在 url 中添加了 rest-api 时;对于这个 url .../test/hello 它返回 404

标签: spring-boot rest http-status-code-404 jboss7.x


【解决方案1】:

您使用的是 7.1.0 对。删除它并尝试server.servlet-path=/*

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-30
    • 2020-01-05
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多