Unable to start Tomcat server with two SpringMVC webapps that are created from same maven archetype

旧城冷巷雨未停 提交于 2020-02-25 07:28:08

问题


I have created two Spring MVC applications using spring-mvc-quickstart-archetype (includes spring mvc, spring security, hibernate) , I could run each of this application seperately on tomcat but not able to together.

when I add both the projects on to Tomcat, server will not comeup, I get

Aug 30, 2013 8:14:48 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'appServlet'

then the next line is error in red text as below and then server gets terminated

Exception in thread "main" 

I enabled Spring log level to DEBUG on the logback.xml, it writes a bunch of log messages with DEBUG and INFO but nothing with WARN or ERROR that shows any insight into what is happening internally.

Has any body come accross this and have found a solution ?

Adding the log as suggested

Sep 13, 2013 8:20:24 AM org.apache.catalina.core.AprLifecycleListener init 
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Programs\Java\jdk1.7.0_21\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Programs/Java/jdk1.6.0_32/bin/../jre/bin/server;C:/Programs/Java/jdk1.6.0_32/bin/../jre/bin;C:/Programs/Java/jdk1.6.0_32/bin/../jre/lib/amd64;c:\Python27;C:\Programs\Java\jdk1.6.0_32\bin;C:\Programs\apache-maven-3.0.4\bin;c:\Programs\mongodb243\bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Programs\eclipse-jee-juno -with-SpringToolSuit;;.
Sep 13, 2013 8:20:24 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:shows' did not find a matching property.
Sep 13, 2013 8:20:24 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:com.maha.science.web' did not find a matching property.
Sep 13, 2013 8:20:24 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-7080"]
Sep 13, 2013 8:20:24 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-7009"]
Sep 13, 2013 8:20:24 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 705 ms
Sep 13, 2013 8:20:25 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 13, 2013 8:20:25 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.25
Sep 13, 2013 8:20:31 AM org.apache.catalina.core.ApplicationContext log
INFO: Spring WebApplicationInitializers detected on classpath:   [com.maha.science.config.WebAppInitializer@c2854c7]
Sep 13, 2013 8:20:31 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Sep 13, 2013 8:20:35 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'appServlet1'
Exception in thread "main" 

回答1:


Venkat,

You need to specify a different root key for each app.

If you're using XML-configuration, then use Karthikenyan's approach, specifying a different value in each web.xml:

<context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>thisisdistinctforeachwebapp</param-value>
</context-param>

If you're using an XML-free configuration (implementing WebApplicationInitializer), it's as easy as one line:

servletContext.setInitParameter("webAppRootKey", "thisisdistinctforeachwebapp"); 

HTH




回答2:


After struggling for sometime this issue finally got resolved, i am writing that worked from me hoping it would help others in similar scenarios.

while experimenteing with logback,xml has given more info on the actual error

SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: PermGen space
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
at java.util.concurrent.FutureTask.get(FutureTask.java:111)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1130)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:293)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

looks like the webapp being heavy with hibernate, spring and other libraries is having a permgen space issue, so i added the VM argument to server as below

-XX:MaxPermSize=128m

Double Click on Server and open Launch Configuration add the above param on VM arguments section, this did the magic.

I have reverted the earlier changes of giving a unique servlet name for appServlet and removed the unique webAppRootKey as context param and it works still.

So to summarize we can run multiple webapps that are created from the same maven quickstart on one tomcat server without any issues as long as we set-XX:MaxPermSize=128m param to server startup.



来源:https://stackoverflow.com/questions/18543317/unable-to-start-tomcat-server-with-two-springmvc-webapps-that-are-created-from-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!