【发布时间】:2020-01-18 20:28:45
【问题描述】:
我正在尝试使用带有 JBoss 工具插件的 STS 将 Spring Boot 应用程序部署到 jboss 中。
如果我将应用程序作为“Spring Boot App”运行,它运行良好,但是当我在 Red Hat 7.2 上使用 EAP 7.2 和 STS 上的 JBoss 收费时,它会返回 404。
我使用的 STS 版本是 3.9.8.RELEASE JBoss Tools插件的版本是3.10.2.v20181101-1129
这是我的 POM 文件:
<?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>
<groupId>org.springframework</groupId>
<artifactId>gs-rest-service</artifactId>
<version>0.1.0</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
这是 SpringApplicationBuilder 的覆盖:
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class SpringInitializer extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
这是我的控制器类:
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}
这是主类:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
这是问候类....以防万一:
public class Greeting {
private final long id;
private final String content;
public Greeting(long id, String content) {
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}
如果我右键单击项目资源管理器,作为 Spring Boot App 运行,应用程序在调用时返回正确的响应:
http://localhost:8080/greeting
Response when running as Spring Boot App
但如果我将它部署到 Jboss,它会退出 404。
当我将它作为服务器运行时,日志会返回:
17:48:15,176 INFO [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 9) Inicializando Mojarra 2.3.5.SP2-redhat-00001 para el contexto '/gs-rest-service-0.1.0'
17:48:15,590 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 9) WFLYUT0021: Contexto de Web registrado: '/gs-rest-service-0.1.0' para el servidor 'default-server'
17:48:15,609 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0010: Implementado "gs-rest-service-0.1.0.war" (runtime-name : "gs-rest-service-0.1.0.war")
我假设,将我的上下文更改为: http://localhost:8080/gs-rest-service-0.1.0/greeting
【问题讨论】:
标签: java spring-boot jboss spring-tool-suite jboss-eap-7