2015-10-06 114 views
1

Wicket和Java Web開發的新手段。我從Wicket網站上獲得了一個快速啓動項目,並且試圖在本地Tomcat服務器上運行它。主頁目前給我一個錯誤:「javax.servlet.ServletException:過濾器執行引發異常」。Tomcat上的Wicket快速入門:Servlet NoSuchMethodError

這裏的堆棧跟蹤:

Oct 05, 2015 10:40:18 PM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet default threw exception 
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z 
at org.apache.wicket.protocol.http.servlet.ServletWebResponse.flush(ServletWebResponse.java:319) 
at org.apache.wicket.protocol.http.HeaderBufferingWebResponse.flush(HeaderBufferingWebResponse.java:99) 
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:263) 
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:203) 
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:284) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) 
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) 
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) 
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 
at java.lang.Thread.run(Thread.java:745) 

我已經添加了tomcat的8庫及其servlet的api.jar文件到我的類路徑。在pom.xml或web.xml中似乎沒有關於servlet的任何信息。我讀過它可能是一個servlet-api版本問題,但mvn安裝似乎正在安裝正確的版本(3.1.0)。以下是pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?> 
<!-- 
Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements. See the NOTICE file distributed with 
this work for additional information regarding copyright ownership. 
The ASF licenses this file to You under the Apache License, Version 2.0 
(the "License"); you may not use this file except in compliance with 
the License. You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 
Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License. 
--> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 

<modelVersion>4.0.0</modelVersion> 
<groupId>com.drat.proteus</groupId> 
<artifactId>proteus</artifactId> 
<packaging>war</packaging> 
<version>1.0-SNAPSHOT</version> 
    <!-- TODO project name --> 
<name>quickstart</name> 
<description></description> 
<!-- 
    <organization> 
     <name>company name</name> 
     <url>company url</url> 
    </organization> 
--> 
<licenses> 
    <license> 
     <name>The Apache Software License, Version 2.0</name> 
     <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> 
     <distribution>repo</distribution> 
    </license> 
</licenses> 
<properties> 
    <wicket.version>7.0.0</wicket.version> 
    <jetty9.version>9.2.11.v20150529</jetty9.version> 
    <log4j.version>2.3</log4j.version> 
    <junit.version>4.12</junit.version> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <!-- allowed values: R7, 1.0, 1.5, 2.0 or none --> 
    <wtp.version>none</wtp.version> 
</properties> 
<dependencies> 
    <!-- WICKET DEPENDENCIES --> 
    <dependency> 
     <groupId>org.apache.wicket</groupId> 
     <artifactId>wicket-core</artifactId> 
     <version>${wicket.version}</version> 
    </dependency> 
    <!-- OPTIONAL DEPENDENCY 
    <dependency> 
     <groupId>org.apache.wicket</groupId> 
     <artifactId>wicket-extensions</artifactId> 
     <version>${wicket.version}</version> 
    </dependency> 
    --> 

    <!-- LOGGING DEPENDENCIES - LOG4J --> 
    <dependency> 
     <groupId>org.apache.logging.log4j</groupId> 
     <artifactId>log4j-slf4j-impl</artifactId> 
     <version>${log4j.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.logging.log4j</groupId> 
     <artifactId>log4j-core</artifactId> 
     <version>${log4j.version}</version> 
    </dependency> 

    <!-- JUNIT DEPENDENCY FOR TESTING --> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>${junit.version}</version> 
     <scope>test</scope> 
    </dependency> 

    <!-- JETTY DEPENDENCIES FOR TESTING --> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-server</artifactId> 
     <version>${jetty9.version}</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-webapp</artifactId> 
     <version>${jetty9.version}</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-util</artifactId> 
     <version>${jetty9.version}</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-jmx</artifactId> 
     <version>${jetty9.version}</version> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 
<build> 
    <resources> 
     <resource> 
      <filtering>false</filtering> 
      <directory>src/main/resources</directory> 
     </resource> 
     <resource> 
      <filtering>false</filtering> 
      <directory>src/main/java</directory> 
      <includes> 
       <include>**</include> 
      </includes> 
      <excludes> 
       <exclude>**/*.java</exclude> 
      </excludes> 
     </resource> 
    </resources> 
    <testResources> 
     <testResource> 
      <filtering>false</filtering> 
      <directory>src/test/resources</directory> 
     </testResource> 
     <testResource> 
      <filtering>false</filtering> 
      <directory>src/test/java</directory> 
      <includes> 
       <include>**</include> 
      </includes> 
      <excludes> 
       <exclude>**/*.java</exclude> 
      </excludes> 
     </testResource> 
    </testResources> 
    <plugins> 
     <plugin> 
      <inherited>true</inherited> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.1</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
       <encoding>UTF-8</encoding> 
       <showWarnings>true</showWarnings> 
       <showDeprecation>true</showDeprecation> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.eclipse.jetty</groupId> 
      <artifactId>jetty-maven-plugin</artifactId> 
      <version>${jetty9.version}</version> 
      <configuration> 
       <systemProperties> 
        <systemProperty> 
         <name>maven.project.build.directory.test-classes</name> 
         <value>${project.build.directory}/test-classes</value> 
        </systemProperty> 
       </systemProperties> 
       <jettyXml>${project.basedir}/src/test/jetty/jetty.xml,${project.basedir}/src/test/jetty/jetty-ssl.xml,${project.basedir}/src/test/jetty/jetty-http.xml,${project.basedir}/src/test/jetty/jetty-https.xml</jettyXml> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-eclipse-plugin</artifactId> 
      <version>2.9</version> 
      <configuration> 
       <downloadSources>true</downloadSources> 
       <wtpversion>${wtp.version}</wtpversion> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

<repositories> 
    <repository> 
     <id>Apache Nexus</id> 
     <url>https://repository.apache.org/content/repositories/snapshots/</url> 
     <releases> 
      <enabled>false</enabled> 
     </releases> 
     <snapshots> 
      <enabled>true</enabled> 
     </snapshots> 
    </repository> 
</repositories> 
</project> 

謝謝!

+0

自從servlet-api 3.0開始存在isAsyncStarted方法,請參閱https://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#isAsyncStarted%28%29您使用哪個servlet API? –

+0

@MartinStrejc當我進行mvn安裝時,servlet-api的所有實例都是3.1.0,但正如我所說的,在pom.xml中沒有提到一個servlet,所以我不確定它是從哪裏來的。我已將pom文件添加到我的帖子中。 – user3622688

+0

POM中的Maven依賴項具有「提供」範圍。這意味着它可以從代碼訪問,它與該庫一起編譯,但它不是最終戰爭的一部分。原因是JAR庫有望成爲共享目錄(例如libs)中的服務器(例如Tomcat)的一部分。見https://github.com/apache/wicket/blob/master/pom.xml –

回答

1

更改版本在web.xml到3.0,現在它仍然是2.5

來自:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
     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_2_5.xsd" 
     version="2.5"> 
... 
</web-app> 

到:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
     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" 
     version="3.0"> 
... 
</web-app> 

或:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
    version="3.1"> 
... 
</web-app> 

也許這有助於。

+0

謝謝!我已經修復了Wicket的快速入門Maven原型。 –

+0

這是否並沒有解決servlet問題。雖然做得非常好。 – user3622688