web-dev-qa-db-ja.com

TomcatサーバーがVaadin7アプリケーションで使用されるサーブレット構成としてweb.xmlファイルを処理しないのはなぜですか?

アプリケーションのサーブレットの構成ファイルとしてweb.xmlを使用すると、Tomcatを起動できません。これは、ファイルの内容です。

<?xml version="1.0" encoding="UTF-8"?>
<web-app
  id="WebApp_ID" version="3.0"
  xmlns="http://Java.Sun.com/xml/ns/j2ee" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://Java.Sun.com/xml/ns/javaee
     http://Java.Sun.com/xml/ns/javaee/web-app_3_0.xsd">

  <servlet>
    <servlet-name>AppLifeServlet</servlet-name>
    <servlet-class>
        com.example.application_lifecycle_chapter_4_7.ApplicatationLifecycleUI.Servlet
    </servlet-class>
    <init-param>
      <param-name>UI</param-name>
      <param-value>com.example.application_lifecycle_chapter_4_7.ApplicationLifecycleUI</param-value>
    </init-param>
    <async-supported>true</async-supported>
  </servlet>

  <servlet>
      <servlet-name>MyPushyServlet</servlet-name>
      <servlet-class>
          com.example.application_lifecycle_chapter_4_7.MyPushyUI.Servlet
      </servlet-class>
      <init-param>
        <param-name>UI</param-name>
        <param-value>com.example.application_lifecycle_chapter_4_7.MyPushyUI</param-value>
      </init-param>
      <async-supported>true</async-supported>
  </servlet>    

  <servlet-mapping>
    <servlet-name>AppLifeServlet</servlet-name>
    <url-pattern>/AppLife/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
      <servlet-name>AppLifeServlet</servlet-name>
      <url-pattern>/VAADIN/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
      <servlet-name>MyPushyServlet</servlet-name>
      <url-pattern>/MyPushyUI/*</url-pattern>
  </servlet-mapping>
</web-app>

なぜ機能しないのですか? Tomcatも起動せず、代わりに例外を返します。

SEVERE: Failed to destroy end point associated with ProtocolHandler ["ajp-nio-8009"]
Java.lang.NullPointerException
    at org.Apache.Tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.Java:307)
    at org.Apache.Tomcat.util.net.NioEndpoint.unbind(NioEndpoint.Java:482)
    at org.Apache.Tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.Java:795)
    at org.Apache.coyote.AbstractProtocol.destroy(AbstractProtocol.Java:531)
    at org.Apache.catalina.connector.Connector.destroyInternal(Connector.Java:1023)
    at org.Apache.catalina.util.LifecycleBase.destroy(LifecycleBase.Java:305)
    at org.Apache.catalina.core.StandardService.destroyInternal(StandardService.Java:588)
    at org.Apache.catalina.util.LifecycleBase.destroy(LifecycleBase.Java:305)
    at org.Apache.catalina.core.StandardServer.destroyInternal(StandardServer.Java:850)
    at org.Apache.catalina.util.LifecycleBase.destroy(LifecycleBase.Java:305)
    at org.Apache.catalina.startup.Catalina.start(Catalina.Java:629)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke(Method.Java:483)
    at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:351)
    at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:485)

Web.xmlを無効にし、サーブレットの3.0 APIアノテーションを使用すると、すべてが機能します...

Web.xmlファイルの何が問題になっていますか?

編集:Tomcatが起動しようとしたときの完全な例外出力は次のとおりです。

SEVERE: A child container failed during start
Java.util.concurrent.ExecutionException: org.Apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Application_Lifecycle_Chapter_4.7]]
    at Java.util.concurrent.FutureTask.report(FutureTask.Java:122)
    at Java.util.concurrent.FutureTask.get(FutureTask.Java:192)
    at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:917)
    at org.Apache.catalina.core.StandardHost.startInternal(StandardHost.Java:868)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1409)
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1399)
    at Java.util.concurrent.FutureTask.run(FutureTask.Java:266)
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1142)
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:617)
    at Java.lang.Thread.run(Thread.Java:745)
Caused by: org.Apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Application_Lifecycle_Chapter_4.7]]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:154)
    ... 6 more
Caused by: Java.lang.IllegalArgumentException: The servlets named [AppLifeServlet] and [com.example.application_lifecycle_chapter_4_7.ApplicationLifecycleUI$Servlet] are both mapped to the url-pattern [/AppLife/*] which is not permitted
    at org.Apache.Tomcat.util.descriptor.web.WebXml.addServletMapping(WebXml.Java:308)
    at org.Apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.Java:2325)
    at org.Apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.Java:2007)
    at org.Apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.Java:1901)
    at org.Apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.Java:1896)
    at org.Apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.Java:1896)
    at org.Apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.Java:1896)
    at org.Apache.catalina.startup.ContextConfig.webConfig(ContextConfig.Java:1139)
    at org.Apache.catalina.startup.ContextConfig.configureStart(ContextConfig.Java:771)
    at org.Apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.Java:305)
    at org.Apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.Java:117)
    at org.Apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.Java:90)
    at org.Apache.catalina.core.StandardContext.startInternal(StandardContext.Java:5095)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    ... 6 more

Dec 07, 2014 7:49:30 PM org.Apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
Java.util.concurrent.ExecutionException: org.Apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at Java.util.concurrent.FutureTask.report(FutureTask.Java:122)
    at Java.util.concurrent.FutureTask.get(FutureTask.Java:192)
    at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:917)
    at org.Apache.catalina.core.StandardEngine.startInternal(StandardEngine.Java:262)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    at org.Apache.catalina.core.StandardService.startInternal(StandardService.Java:439)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    at org.Apache.catalina.core.StandardServer.startInternal(StandardServer.Java:760)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    at org.Apache.catalina.startup.Catalina.start(Catalina.Java:625)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke(Method.Java:483)
    at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:351)
    at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:485)
Caused by: org.Apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:154)
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1409)
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1399)
    at Java.util.concurrent.FutureTask.run(FutureTask.Java:266)
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1142)
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:617)
    at Java.lang.Thread.run(Thread.Java:745)
Caused by: org.Apache.catalina.LifecycleException: A child container failed during start
    at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:925)
    at org.Apache.catalina.core.StandardHost.startInternal(StandardHost.Java:868)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    ... 6 more

Dec 07, 2014 7:49:30 PM org.Apache.catalina.startup.Catalina start
SEVERE: The required Server component failed to start so Tomcat is unable to start.
org.Apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:154)
    at org.Apache.catalina.startup.Catalina.start(Catalina.Java:625)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke(Method.Java:483)
    at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:351)
    at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:485)
Caused by: org.Apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:154)
    at org.Apache.catalina.core.StandardServer.startInternal(StandardServer.Java:760)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    ... 7 more
Caused by: org.Apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:154)
    at org.Apache.catalina.core.StandardService.startInternal(StandardService.Java:439)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    ... 9 more
Caused by: org.Apache.catalina.LifecycleException: A child container failed during start
    at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:925)
    at org.Apache.catalina.core.StandardEngine.startInternal(StandardEngine.Java:262)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    ... 11 more

Dec 07, 2014 7:49:30 PM org.Apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-nio-8080"]
Dec 07, 2014 7:49:30 PM org.Apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-nio-8009"]
Dec 07, 2014 7:49:30 PM org.Apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Dec 07, 2014 7:49:30 PM org.Apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-nio-8080"]
Dec 07, 2014 7:49:30 PM org.Apache.coyote.AbstractProtocol destroy
SEVERE: Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]
Java.lang.NullPointerException
    at org.Apache.Tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.Java:307)
    at org.Apache.Tomcat.util.net.NioEndpoint.unbind(NioEndpoint.Java:482)
    at org.Apache.Tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.Java:795)
    at org.Apache.coyote.AbstractProtocol.destroy(AbstractProtocol.Java:531)
    at org.Apache.catalina.connector.Connector.destroyInternal(Connector.Java:1023)
    at org.Apache.catalina.util.LifecycleBase.destroy(LifecycleBase.Java:305)
    at org.Apache.catalina.core.StandardService.destroyInternal(StandardService.Java:588)
    at org.Apache.catalina.util.LifecycleBase.destroy(LifecycleBase.Java:305)
    at org.Apache.catalina.core.StandardServer.destroyInternal(StandardServer.Java:850)
    at org.Apache.catalina.util.LifecycleBase.destroy(LifecycleBase.Java:305)
    at org.Apache.catalina.startup.Catalina.start(Catalina.Java:629)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke(Method.Java:483)
    at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:351)
    at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:485)

Dec 07, 2014 7:49:30 PM org.Apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-nio-8009"]
Dec 07, 2014 7:49:30 PM org.Apache.coyote.AbstractProtocol destroy
SEVERE: Failed to destroy end point associated with ProtocolHandler ["ajp-nio-8009"]
Java.lang.NullPointerException
    at org.Apache.Tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.Java:307)
    at org.Apache.Tomcat.util.net.NioEndpoint.unbind(NioEndpoint.Java:482)
    at org.Apache.Tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.Java:795)
    at org.Apache.coyote.AbstractProtocol.destroy(AbstractProtocol.Java:531)
    at org.Apache.catalina.connector.Connector.destroyInternal(Connector.Java:1023)
    at org.Apache.catalina.util.LifecycleBase.destroy(LifecycleBase.Java:305)
    at org.Apache.catalina.core.StandardService.destroyInternal(StandardService.Java:588)
    at org.Apache.catalina.util.LifecycleBase.destroy(LifecycleBase.Java:305)
    at org.Apache.catalina.core.StandardServer.destroyInternal(StandardServer.Java:850)
    at org.Apache.catalina.util.LifecycleBase.destroy(LifecycleBase.Java:305)
    at org.Apache.catalina.startup.Catalina.start(Catalina.Java:629)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke(Method.Java:483)
    at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:351)
    at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:485)

解決済み:これは重要な行です:

 Caused by: Java.lang.IllegalArgumentException: The servlets named [AppLifeServlet] and 
    [com.example.application_lifecycle_chapter_4_7.ApplicationLifecycleUI$Servlet] are both 
    mapped to the url-pattern [/AppLife/*] which is not permitted

ヴァーディンの書から:

同じアプリケーションでweb.xmlとWebServletの両方を使用できます。 web.xmlの設定は、注釈で指定された設定を上書きします。

これは真実ではありません!私の場合、エラーは次のフレーズが原因でした。@WebServletApplicationLifecycleUI$Servletアノテーションがあり、web.xmlファイル内のサーブレットマッピングも含まれていました。

2つの構成は共存できないため、URLマッピングにweb.xmlまたは@WebServletアノテーションを使用するかどうかを選択する必要があります。そうしないと、Tomcatを起動しようとしたときにこのエラーが発生します。

7
tonix

@tonixからのコメントは実際に真実であることがわかりました。アノテーションとweb.xmlは共存できません。アノテーションを保持したい場合は、web.xmlを削除する必要があります。

さらに、すべてのurl-patternがweb.xmlにあるか、注釈にあるかを確認するだけです。それらは正しいはずです。つまり、通常、接頭辞「/」(スラッシュ)を付ける必要があります。

これらの変更を行った後、Tomcatを再起動してみてください。これは、私の非常によく似たケースで機能するはずです。

4
Jaydeep Ranipa