java - Jboss中的Spring Boot返回错误404
问题描述
我有一个示例 Spring Boot 应用程序。它适用于 Tomcat 服务器,但是当我生成战争并将其部署在 jboss 服务器(7.1.1)中时,出现 404 错误。
这是我的 restController 示例:
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController {
@RequestMapping(value="/test")
public String sayHello() {
return "Hello Spring Boot!!";
}
}
这是我的主要课程:
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 MainApp extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MainApp.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MainApp.class);
}
}
我添加了一个 application.properties 文件,并在其中添加了这一行:
server.contextPath = /*
我的 jbos-web.xml 是这样的:
> <?xml version="1.0" encoding="UTF-8"?> <!-- this is really not
> needed... you can just build (or rename WAR file to)
> spring-boot-jboss.war
> --> <!DOCTYPE jboss-web> <jboss-web> <context-root>/test</context-root> </jboss-web>
最后我的 pom.xml 如下:
<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.boraji.tutorial.springboot</groupId>
<artifactId>spring-boot-hello-world-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<java.version>1.7</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<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>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我使用以下 url 运行应用程序: http://localhost:8080/test/test 但返回 404 错误。
谢谢您的帮助。
解决方案
我在 JBoss EAP 6.4 / spring boot 1.5 上遇到了同样的问题,添加这个属性的问题是什么
server.servlet-path=/*
如本文所述:在 JBOSS EAP 6.1 上部署 spring boot
但是在 JBoss EAP 7.1 上没有这个属性它工作得很好。
推荐阅读
- ios - Apple Fitness - 更改锻炼列表中显示的值
- linux - OpenSuse Linux 通过文件名中的字符串查找文件
- android - 从android中的子项目添加活动类
- java - 我有返回连接的方法,该连接是从我的 tomcat jndi 获取的,我应该关闭 DataSource 对象以防止内存泄漏吗?Tomcat9
- python - 如何将表单重定向到视图中的面板选项卡?
- python - 删除未使用的库 python pyproject.toml
- javascript - 试图绕过在文本字段上执行聚合
- java - micronaut 将 @Validation 应用于入站控制器 POJO 未验证
- python - 如何关联国家和发票以打印自定义文本?
- wordpress - 自定义支付字段