无法在jBoss EAP 6.3.3上部署Spring Boot

时间:2015-09-30 15:55:14

标签: spring jboss spring-boot

我正在使用Spring Tool Suite版本:3.7.0.RELEASE使用tc服务器部署Spring启动项目,该工作正常但在JBoss EAP 6.1+上失败。我得到一个JBWEB000065:HTTP状态404 - / shell /

ShellApplication.java

@SpringBootApplication
@ComponentScan("shell")
public class ShellApplication extends SpringBootServletInitializer {

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

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

的src /主/ web应用/ WEB-INF / JBoss的-web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <context-root>/</context-root>
</jboss-web>

控制台日志

13:41:36,460 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015876: Starting deployment of "shell.war" (runtime-name: "shell.war")
13:42:15,089 INFO  [org.jboss.web] (ServerService Thread Pool -- 53) JBAS018210: Register web context: /shell
13:42:17,332 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "shell.war" (runtime-name : "shell.war")

浏览器

JBWEB000065: HTTP Status 404 - /shell/

--------------------------------------------------------------------------------

JBWEB000309: type JBWEB000067: Status report

JBWEB000068: message /shell/

JBWEB000069: description JBWEB000124: The requested resource is not available.

2 个答案:

答案 0 :(得分:0)

我遇到了完全相同的问题,终于找到了解决方案。
请尝试以下步骤:

1.在pom.xml中:

<dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>javax.servlet-api</artifactId>
   <scope>provided</scope>
</dependency>

2。添加一个实现WebApplicationInitializer的类:

@Configuration
public class WebApplicationInitializerImpl implements WebApplicationInitializer{

    @Override 
    public void onStartup(ServletContext container) throws ServletException {
        WebApplicationContext context = getContext();

        Dynamic registration = container.addServlet("dispatcher", new DispatcherServlet(context));
        registration.setLoadOnStartup(1);
        registration.addMapping("/*");
    } 

    private WebApplicationContext getContext() { 
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.setConfigLocation(ApplicationMain.class.getName());
        return context;
    } 

}

3。记住要通过您的应用程序扩展SpringBootServletInitializer:

@SpringBootApplication
public class ApplicationMain extends SpringBootServletInitializer{

   @Override
   protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
      return builder.sources(ApplicationMain.class);
   }

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

有关更多说明,我在另一个问题中回答了:Spring boot war not working on EAP 6
希望能帮助到你。

答案 1 :(得分:0)

我在JBoss EAP 6.4 / spring boot 1.5上遇到了同样的问题,并且解决了将该属性添加到application.properties的问题。

server.servlet-path=/*

如这篇文章中所述:Deploying spring boot on JBOSS EAP 6.1