abd*_*men 5 java jboss spring spring-boot
我有一个示例 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!!";
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的主课:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我添加了一个 application.properties 文件,并在其中添加了这一行:
服务器.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>
Run Code Online (Sandbox Code Playgroud)
最后我的 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>
Run Code Online (Sandbox Code Playgroud)
我使用以下网址运行应用程序: http://localhost:8080/test/test 但返回了 404 错误。
感谢您的帮助。
小智 3
我在 JBoss EAP 6.4 / spring boot 1.5 上遇到了同样的问题,解决方法是添加此属性
server.servlet-path=/*
Run Code Online (Sandbox Code Playgroud)
如这篇文章中所述:在 JBOSS EAP 6.1 上部署 spring boot
不过,在 JBoss EAP 7.1 上,如果没有这个属性,它也能正常工作。
| 归档时间: |
|
| 查看次数: |
3502 次 |
| 最近记录: |