问题
I am currently having an issue deploying a WAR file to my Tomcat7 server (Im new to web dev with java). Everything works great in eclipse but when I generate a WAR file and deploy it to the server I get the following error. "Failed to start component []" Below is the log dump.
Caused by: org.apache.catalina.LifecycleException: Failed to process either the global, per-host or context-specific context.xml file therefore the [] Context cannot be started.
at org.apache.catalina.startup.FailedContext.startInternal(FailedContext.java:158)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 31 more
Oct 13, 2014 7:22:56 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: list: Listing contexts for virtual host 'mysite.com'
Oct 13, 2014 7:23:11 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLHostManager: list: Listing hosts for engine [Catalina]
Oct 13, 2014 8:05:48 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: list: Listing contexts for virtual host 'mysite.com'
Oct 13, 2014 8:06:08 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: start: Starting web application '/'
Oct 13, 2014 8:06:08 PM org.apache.catalina.core.ApplicationContext log
SEVERE: FAIL - Application at context path / could not be started
org.apache.catalina.LifecycleException: Failed to start component []
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1291)
at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:694)
at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:217)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:190)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to process either the global, per-host or context-specific context.xml file therefore the [] Context cannot be started.
at org.apache.catalina.startup.FailedContext.startInternal(FailedContext.java:158)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 31 more
When I remove my /META-INF/context.xml file it seems to load just fine however I cant use my DB connection.
My context.xml is below.
<context>
<Resource name="jdbc/mysitedb" auth="Container"
maxActive="100" maxIdle="30" maxWait="10000"
username="myusername" password="mypassword"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://www.mysite.com/mysitedb?autoReconnect=true"
logAbandoned="true" removeAbandoned="true"
removeAbandonedTimeout="60" type="javax.sql.DataSource" />
</context>
I am new to JSP so any help would be greatly appreciated.
回答1:
If that's really your complete context.xml, you need to wrap it in a Context element:
<Context>
<Resource name="jdbc/mysitedb" auth="Container"
maxActive="100" maxIdle="30" maxWait="10000"
username="myusername" password="mypassword"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://www.mysite.com/mysitedb?autoReconnect=true"
logAbandoned="true" removeAbandoned="true"
removeAbandonedTimeout="60" type="javax.sql.DataSource" />
</Context>
Your Tomcat is attempting to load an unnamed component. Could be that broken context.xml. You can get similar errors for a broken web.xml.
来源:https://stackoverflow.com/questions/26348210/trouble-deploying-war-file-failed-to-start-component