Java Spring boot war在EAP 6上不起作用

Java Spring boot war在EAP 6上不起作用,java,spring-mvc,spring-boot,jboss,Java,Spring Mvc,Spring Boot,Jboss,我使用SpringBoot创建了一个基于REST的小应用程序。该应用程序作为war包部署在EAP 6(JBoss)上。 由于EAP6基于Java1.7,我在maven pom中配置了它,以编译和使用Java1.7版本。 当我部署应用程序时,我可以在服务器日志中看到控制器正在注册,但当我点击它时,我会看到404。另外,我JBoss没有选择我的上下文根配置,而是将应用程序名作为上下文根。我测试了所有可能的端点,但所有的都是404。 有人能给我一些建议,帮助我继续前进吗 POM文件: <

我使用SpringBoot创建了一个基于REST的小应用程序。该应用程序作为war包部署在EAP 6(JBoss)上。 由于EAP6基于Java1.7,我在maven pom中配置了它,以编译和使用Java1.7版本。 当我部署应用程序时,我可以在服务器日志中看到控制器正在注册,但当我点击它时,我会看到404。另外,我JBoss没有选择我的上下文根配置,而是将应用程序名作为上下文根。我测试了所有可能的端点,但所有的都是404。 有人能给我一些建议,帮助我继续前进吗

POM文件:

    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.7</java.version>
</properties>
}

package com.org.orderhistory.v2.orderhistory.v2.controllers;
导入。。。
@RestController
@请求映射(value=“/myorder/weborders”)
公共类WebOrderController{
@RequestMapping(value=“/{webUserId}”,method=RequestMethod.GET,products=“application/json”)
公共列表getWebOrdersForUser(@PathVariable Long webUserId){
JBoss日志

2017-10-09 02:24:29,744 [ServerService Thread Pool -- 594] INFO  [org.springframework.boot.web.servlet.FilterRegistrationBean] Mapping filter: 'requestContextFilter' to: [/*]
2017-10-09 02:24:30,368 [ServerService Thread Pool -- 594] INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5a46b924: startup date [Mon Oct 09 02:24:27 EDT 2017]; root of context hierarchy
2017-10-09 02:24:30,451 [ServerService Thread Pool -- 594] INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] Mapped "{[/org/weborders/{webUserId}],methods=[GET],produces=[application/json]}" onto public java.util.List<com.org.www.order.model.WebOrder> com.org.orderhistory.v2.orderhistory.v2.controllers.WebOrderControllers.getWebOrdersForUser(java.lang.Long)
2017-10-09 02:24:29744[ServerService线程池--594]信息[org.springframework.boot.web.servlet.FilterRegistrationBean]映射筛选器:“requestContextFilter”到:[/*]
2017-10-09 02:24:30368[ServerService线程池--594]信息[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]正在查找@ControllerAdvice:org.springframework.boot.context.embedded。AnnotationConfigEmbeddedWebApplicationContext@5a46b924:启动日期[2017年10月9日星期一02:24:27 EDT];上下文层次结构的根
2017-10-09 02:24:30451[ServerService线程池--594]信息[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]映射“{[/org/weborders/{webUserId}],methods=[GET],products=[application/json]}”到public java.util.List com.org.orderhistory.v2.orderhistory.v2.controllers.WebOrderControllers.getwebordersfourser(java.lang.Long)

此处的问题完全相同。请尝试以下操作:

1.在pom.xml中:

<dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>javax.servlet-api</artifactId>
   <scope>provided</scope>
</dependency>
3.记住通过应用程序扩展SpringBootServletilizer:

@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);
   }
}
如果可行,则问题与dispatcherServlet有关。
使用Spring boot时,应自动配置dispatcherServlet(这是自动配置的一部分)
根据Redhat的解释,这种情况似乎是jboss的问题:

因为JBoss强制执行servlet规范中关于不注册冲突映射的要求,即使是为自己的服务器添加的DefaultServlet

要检查dispatcherServlet是否按预期注册,请尝试以下操作:

[standalone@localhost:9999 /] /deployment=spring-boot-application.war/subsystem=web:read-resource(recursive=true)
不工作:

{
    "outcome" => "success",
    "result" => {
        "context-root" => "/spring-boot-application",
        "servlet" => undefined,
        "virtual-host" => "default-host"
    }
}
工作:

{
    "outcome" => "success",
    "result" => {
        "context-root" => "/spring-boot-application",
        "virtual-host" => "default-host",
        "servlet" => {"appServlet" => {
            "servlet-class" => "org.springframework.web.servlet.DispatcherServlet",
            "servlet-name" => "appServlet"
        }}
    }
}
希望它能解决您的问题。

参考资料:

@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);
   }
}
[standalone@localhost:9999 /] /deployment=spring-boot-application.war/subsystem=web:read-resource(recursive=true)
{
    "outcome" => "success",
    "result" => {
        "context-root" => "/spring-boot-application",
        "servlet" => undefined,
        "virtual-host" => "default-host"
    }
}
{
    "outcome" => "success",
    "result" => {
        "context-root" => "/spring-boot-application",
        "virtual-host" => "default-host",
        "servlet" => {"appServlet" => {
            "servlet-class" => "org.springframework.web.servlet.DispatcherServlet",
            "servlet-name" => "appServlet"
        }}
    }
}