如何访问部署在 JBoss AS 7 中的 spring 启动应用程序?

How to access a spring boot application deployed in JBoss AS 7?

我是 spring mvc 的新手,我已经按照 starter guide 导入 hello web 应用程序(Service Web Content 在 Spring 工具套房)。它作为使用嵌入式 Tomcat servlet 的独立应用程序运行良好。

然后我开始打包应用程序as a war。实际采取的步骤如下:

  1. 使应用程序 class 扩展 SpringBootServletInitializer 并添加 SpringApplicationBuilder 配置方法。
  2. 将嵌入式 tomcat 设置为 provided
  3. 将 Maven 打包设置为 war

但是在将 gs-serving-web-content-initial.war 导出并部署到 jboss AS 7 之后,我找不到访问该应用程序的方法!

http://localhost:8080/greetinghttp://localhost:8080/gs-serving-web-content-initial/greeting都给出了相同的404 The requested resource (/greeting) is not available.。 (之前使用结构构建的另一个 war 经过测试可以在同一个 jboss 上正常工作)

添加 也不起作用。那我错过了什么?

更新 20151217:

相关JBoss日志附加如下。 warning (JBAS011006) 在部署时显示 war 但它似乎是 normal for spring wars

09:06:06,107 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "gs-serving-web-content-initial.war"
09:06:06,970 WARN  [org.jboss.as.ee] (MSC service thread 1-2) JBAS011006: Not installing optional component org.springframework.http.server.ServletServerHttpAsyncRequestControl due to exception: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011054: Could not find default constructor for class org.springframework.http.server.ServletServerHttpAsyncRequestControl
    at org.jboss.as.ee.component.ComponentDescription$DefaultComponentConfigurator.configure(ComponentDescription.java:606)
    at org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor.deploy(EEModuleConfigurationProcessor.java:81)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_91]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_91]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_91]

09:06:06,971 WARN  [org.jboss.as.ee] (MSC service thread 1-2) JBAS011006: Not installing optional component org.springframework.web.context.request.async.StandardServletAsyncWebRequest due to exception: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011054: Could not find default constructor for class org.springframework.web.context.request.async.StandardServletAsyncWebRequest
    at org.jboss.as.ee.component.ComponentDescription$DefaultComponentConfigurator.configure(ComponentDescription.java:606)
    at org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor.deploy(EEModuleConfigurationProcessor.java:81)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_91]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_91]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_91]

09:06:07,142 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/gs-serving-web-content-initial]] (MSC service thread 1-2) Spring WebApplicationInitializers detected on classpath: [org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration@52fd8833, hello.Application@2f8f6d6]
09:06:08,149 INFO  [stdout] (MSC service thread 1-2) 
09:06:08,149 INFO  [stdout] (MSC service thread 1-2)   .   ____          _            __ _ _
09:06:08,149 INFO  [stdout] (MSC service thread 1-2)  /\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
09:06:08,149 INFO  [stdout] (MSC service thread 1-2) ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
09:06:08,149 INFO  [stdout] (MSC service thread 1-2)  \/  ___)| |_)| | | | | || (_| |  ) ) ) )
09:06:08,149 INFO  [stdout] (MSC service thread 1-2)   '  |____| .__|_| |_|_| |_\__, | / / / /
09:06:08,149 INFO  [stdout] (MSC service thread 1-2)  =========|_|==============|___/=/_/_/_/
09:06:08,150 INFO  [stdout] (MSC service thread 1-2)  :: Spring Boot ::        (v1.3.0.RELEASE)
09:06:08,150 INFO  [stdout] (MSC service thread 1-2) 
09:06:08,241 INFO  [hello.Application] (MSC service thread 1-2) Starting Application on localhost.localdomain with PID 16909 (started by jboss in /usr/share/jboss-as-7.1.1.Final)
09:06:08,242 INFO  [hello.Application] (MSC service thread 1-2) No profiles are active
09:06:08,456 INFO  [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] (MSC service thread 1-2) Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@116d77df: startup date [Thu Dec 17 09:06:08 HKT 2015]; root of context hierarchy
09:06:09,278 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-2) Overriding bean definition for bean 'beanNameViewResolver' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
09:06:09,537 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (MSC service thread 1-2) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
09:06:09,580 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/gs-serving-web-content-initial]] (MSC service thread 1-2) Initializing Spring embedded WebApplicationContext
09:06:09,581 INFO  [org.springframework.web.context.ContextLoader] (MSC service thread 1-2) Root WebApplicationContext: initialization completed in 1126 ms
09:06:10,062 INFO  [org.springframework.boot.context.embedded.ServletRegistrationBean] (MSC service thread 1-2) Mapping servlet: 'dispatcherServlet' to [/]
09:06:10,063 INFO  [org.springframework.boot.context.embedded.FilterRegistrationBean] (MSC service thread 1-2) Mapping filter: 'errorPageFilter' to: [/*]
09:06:10,063 INFO  [org.springframework.boot.context.embedded.FilterRegistrationBean] (MSC service thread 1-2) Mapping filter: 'characterEncodingFilter' to: [/*]
09:06:10,063 INFO  [org.springframework.boot.context.embedded.FilterRegistrationBean] (MSC service thread 1-2) Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
09:06:10,063 INFO  [org.springframework.boot.context.embedded.FilterRegistrationBean] (MSC service thread 1-2) Mapping filter: 'httpPutFormContentFilter' to: [/*]
09:06:10,063 INFO  [org.springframework.boot.context.embedded.FilterRegistrationBean] (MSC service thread 1-2) Mapping filter: 'requestContextFilter' to: [/*]
09:06:10,208 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (MSC service thread 1-2) Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@116d77df: startup date [Thu Dec 17 09:06:08 HKT 2015]; root of context hierarchy
09:06:10,347 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-2) Mapped "{[/greeting]}" onto public java.lang.String hello.GreetingController.greeting(java.lang.String,org.springframework.ui.Model)
09:06:10,349 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-2) Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
09:06:10,349 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-2) Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
09:06:10,374 INFO  [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (MSC service thread 1-2) Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
09:06:10,375 INFO  [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (MSC service thread 1-2) Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
09:06:10,451 INFO  [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (MSC service thread 1-2) Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
09:06:10,896 INFO  [org.springframework.jmx.export.annotation.AnnotationMBeanExporter] (MSC service thread 1-2) Registering beans for JMX exposure on startup
09:06:11,231 INFO  [hello.Application] (MSC service thread 1-2) Started Application in 3.996 seconds (JVM running for 78143.668)
09:06:11,235 INFO  [org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /gs-serving-web-content-initial
09:06:11,269 INFO  [org.jboss.as.server] (HttpManagementService-threads - 4) JBAS018559: Deployed "gs-serving-web-content-initial.war"

经过 2 天的调查/搜索,我想我会在此处标记我的发现作为答案。

  1. 向 war 添加 jboss-web.xml 有一些效果,但必须在正确的路径中。

将以下内容 jboss-web.xml 添加到 gs-serving-web-content-initial。war\WEB-INF:

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

JBoss 将使用请求的上下文路径:

09:53:57,523 INFO  [hello.Application] (MSC service thread 1-1) Started Application in 3.192 seconds (JVM running for 167409.96)
09:53:57,541 INFO  [org.jboss.web] (MSC service thread 1-1) JBAS018210: Registering web context: /myapp
09:53:57,591 INFO  [org.jboss.as.server] (HttpManagementService-threads - 7) JBAS018559: Deployed "gs-serving-web-content-initial.war"

然而,这对 404 问题根本没有帮助,因此上下文名称不应该是原因。

  1. Spring 引导应用程序在 JBoss 7.
  2. 上运行不正常

根据 this article,JBoss 7.1.1 Final(我也在使用它)似乎在 spring 启动应用程序和 Spring 上表现异常DispatcherServletnot get instantiated properly。我想这会导致 /greeting 的映射失败,从而导致 404 错误。

结论:

链接文章中的解决方案太复杂,我无法遵循,而且似乎也不值得这样做,因为我正在开始一个新项目而不是迁移。我想我会放弃 Spring 引导并回退到简单的 Spring MVC。

如果我遗漏了什么请告诉我,否则我会在明天标记已回答的问题。谢谢大家!

我在 spring boot 1.3.3 应用程序和 jboss eap 6 上遇到了同样的问题。4.x。

Spring 引导使用“/”作为主调度程序 servlet 的默认路径,jboss 没有正确理解(或 "too much correctly")并将 servlet 调度程序映射到“/”而不是“/*”,如您的日志中所述:

09:06:10,062 INFO [org.springframework.boot.context.embedded.ServletRegistrationBean] (MSC service thread 1-2) Mapping servlet: 'dispatcherServlet' to [/] ...

尝试使用 spring 引导应用程序的 application.properties 更改为其他内容,例如 /xxx 或 /*:

server.servlet-path=/*

现在,jboss 正确地将调度程序 servlet 映射到“/xxx/*”,resp。 '/*'.