我是Spring mvc的新手,我已经按照入门指南导入了Spring工具套件中的Hello web
应用程序(Service Web Content
)。它使用嵌入式Tomcat servlet作为独立应用程序运行良好。
然后,我开始将应用程序打包为战争。实际采取的步骤如下:
war
但出口后,
两者都http://localhost:8080/greeting
和http://localhost:8080/gs-为web内容提供首字母/问候语
会提供相同的404请求的资源(/greeting)不可用
。(之前使用structs构建的另一个war在同一jboss上测试运行良好)
添加JBossWeb。xml也不起作用。那么我错过了什么?
更新20151217:
相关JBoss日志附加如下。在部署战争时会显示一条警告(JBAS011006),但在Spring战争中这似乎很正常?
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"
经过两天的调查/搜索,我想我会在这里标记我的发现作为答案。
jboss-web.xml
有一些效果,但它必须在正确的路径上。添加以下jbossweb。xml
到gs服务web内容初始值。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问题没有任何帮助,因此上下文名称不应该是原因。
根据本文,JBoss7.1。1 Final(我也在使用它)在spring启动应用程序上的行为似乎很奇怪,spring的DispatcherServlet
将无法正确实例化。我想这会导致
/greeting
的映射失败,从而导致404错误。
结论:
链接文章中的解决方案对我来说太复杂了,我无法遵循,而且似乎也不值得这么做,因为我正在启动一个新项目,而不是迁移。我想我会放弃SpringBoot,转而使用简单的SpringMVC。
如果我遗漏了什么,请告诉我,否则我会记下明天回答的问题。谢谢大家!
我在spring boot 1.3中也遇到了同样的问题。3应用程序和jboss eap 6.4。十、
Spring boot使用“/”作为主调度程序servlet的默认路径,jboss无法正确理解(或“正确理解得太多”),并将servlet调度程序映射到“/”而不是“/*”,如日志中所述:
09:06:10062信息[org.springframework.boot.context.embedded.ServletRegistrationBean](MSC服务线程1-2)将servlet:“dispatcherServlet”映射到[/]。。。
尝试使用应用程序更改为其他内容,例如/xxx或/*。spring boot应用程序的属性:
server.servlet-path=/*
现在,jboss正确地将DispatcherServlet映射到“/xxx/*”,resp./*”。
我在部署带有Spring启动的 react nodejs 应用程序时遇到问题。Spring应用程序在基本的HTML / JS中工作正常,并且我已经使react应用程序在开发模式下运行良好,但是我似乎缺少一些东西,即正确捆绑反应和Spring。 目前,我可以使用一些简单的HTML和javax调用来运行/部署我的Spring启动应用程序(没有反应)。它在我的 AWS ec2 上运行,没有问题。 我还可
多年来,我一直在这个网站上看到有人问这个问题,但没有一个解决方案对我有效。我正在尝试使用AWS Elastic Beanstalk启动spring boot应用程序。我得到了“502坏网关nginx/1.20.0”错误,许多其他人都得到了。查看我的日志,上面写着“连接()失败(111:连接被拒绝),同时连接到上游,客户端:172.31.16.189,服务器:,请求:“GET/HTTP/1.1”,上
我使用教程创建了一个spring-boot应用程序,并使用'mvn clean install'命令成功地构建了该应用程序。之后,我执行'mvnspring-boot:run'命令来运行应用程序,它也成功地部署了。但是,当我通过点击http://localhost:8080/api在浏览器上加载页面时,它总是重定向到我几个月前部署的http://localhost:8080/login。我应该如何
我刚刚遇到了一个奇怪的问题,这是我第一次在服务器上部署spring boot应用程序 像往常一样,我使用java命令java-jar myApp运行应用程序。罐子 过了一会儿,我看到应用程序停止了,没有留下任何错误消息。 所以我不知道问题出在哪里, 可能的原因是java内存不够,所以我将其增加到7GB,因为它有套接字 但问题依然存在 请注意,我没有docker,服务器是Amazon light s
我是JBoss AS的新手。我正在尝试将我的web应用程序从“pivotal tc server”部署到“JBOSS AS 7.1” 我删除了“pivotal tc server”,只保留JBoss作为7.1 运行服务器后,控制台中会显示以下消息。。。 15: 07:29488信息[org.jboss.modules]jboss模块版本1.1.1。乔治亚州 15: 07:31595信息[org.j
我尝试使用本地主机url访问我的endpoint——http://localhost:8080/这是我的Application.java文件 这是我的终点 我试着用这个网址http://localhost:8080/all