尝试在Jboss 7.2中部署Spring应用程序时出现问题,并出现Servlet初始化错误

时间:2019-04-25 20:05:18

标签: java spring spring-mvc web jboss

我有一个 Spring MVC 应用程序,使用的版本是 4.3.11 4.3.23 ,其中Jboss 6.4在其中运行正确,但是当迁移到Jboss 7.2时,我们会得到

  

java.lang.IllegalStateException:UT010041:Servlet上下文已经被初始化,只能在部署时从ServletContainerInitializer或ServletContextListener调用此方法。

这似乎与从Jboss到Undertow的更改有关,但是我不明白我需要做些什么来解决它并使应用程序正常工作。

我最初发现它与使用 Spring 4.3.11 有关,并已升级到 Spring 4.3.23 ,并且还已升级至 JavaEE 规格为8。但是在两个版本中,问题仍然存在。

  

11:27:09,088错误[org.jboss.msc.service.fail](ServerService线程池-93)MSC000001:无法启动服务jboss.deployment.unit。“ sampleDojo-app-1.0.0-SNAPSHOT .war”。undertow部署:服务jboss.deployment.unit中的org.jboss.msc.service.StartException。“ sampleDojo-app-1.0.0-SNAPSHOT.war”。undertow部署:java.lang.IllegalStateException:UT010041 :Servlet上下文已经初始化,您只能从ServletContainerInitializer或ServletContextListener调用此方法

     

at org.wildfly.extension.undertow.deployment.UndertowDeploymentService $ 1.run(UndertowDeploymentService.java:81)       在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)       在java.util.concurrent.FutureTask.run(FutureTask.java:266)       在org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)       在org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)       在org.jboss.threads.EnhancedQueueExecutor $ ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)       在org.jboss.threads.EnhancedQueueExecutor $ ThreadBody.run(EnhancedQueueExecutor.java:1378)       在java.lang.Thread.run(Thread.java:748)       在org.jboss.threads.JBossThread.run(JBossThread.java:485)   引起原因:java.lang.IllegalStateException:UT010041:Servlet上下文已经初始化,您只能从ServletContainerInitializer或ServletContextListener调用此方法。       在io.undertow.servlet.spec.ServletContextImpl.ensureNotInitialized(ServletContextImpl.java:955)       在io.undertow.servlet.spec.ServletContextImpl.addFilter(ServletContextImpl.java:630)       在br.com.itau.internet.core.impl.web.BaseAnnotationConfigServlet.addServletFilter(BaseAnnotationConfigServlet.java:67)       在br.com.itau.internet.core.impl.web.BaseAnnotationConfigServlet.addServletFilters(BaseAnnotationConfigServlet.java:46)       在br.com.itau.internet.core.impl.web.BaseAnnotationConfigServlet.initWebApplicationContext(BaseAnnotationConfigServlet.java:29)       在org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)       在org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:171)       在javax.servlet.GenericServlet.init(GenericServlet.java:244)       在io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)       在org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78)处       在io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103)       在io.undertow.servlet.core.ManagedServlet $ DefaultInstanceStrategy.start(ManagedServlet.java:303)       在io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:143)       在io.undertow.servlet.core.DeploymentManagerImpl $ 2.call(DeploymentManagerImpl.java:583)       在io.undertow.servlet.core.DeploymentManagerImpl $ 2.call(DeploymentManagerImpl.java:554)       在io.undertow.servlet.core.ServletRequestContextThreadSetupAction $ 1.call(ServletRequestContextThreadSetupAction.java:42)       在io.undertow.servlet.core.ContextClassLoaderSetupAction $ 1.call(ContextClassLoaderSetupAction.java:43)       在org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda $ create $ 0(SecurityContextThreadSetupAction.java:105)       在org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1502)       在org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1502)       在org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1502)       在org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1502)       在io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:596)       在org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:97)       在org.wildfly.extension.undertow.deployment.UndertowDeploymentService $ 1.run(UndertowDeploymentService.java:78)       ...另外8个

不幸的是,在迁移到Spring 5时,我没有选择,我需要这些应用程序才能在Spring 4.x中工作。

我到处都看过,但是我仍然不知道出什么问题了。

在调试应用程序时,我发现尝试添加过滤器时发生错误

final ServletRegistration.Dynamic sr = getServletContext().addServlet(servlet.getServletName(), servlet.getServletClass());
        sr.addMapping(servlet.getServletPath());
        sr.setLoadOnStartup(1);

0 个答案:

没有答案