缺少servlet api 3.0 jar中的异步方法?

时间:2013-04-16 16:02:54

标签: java asynchronous servlet-3.0

我正在开发一个servlet 3.0应用程序,它必须异步处理请求。

编译失败并带有

cannot find symbol
symbol  : method startAsync(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
location: interface javax.servlet.http.HttpServletRequest

消息。

我的 pom.xml

中有以下依赖项
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>6.0</version>
</dependency>

有趣的是, import javax.servlet.AsyncContext 会成功。但是当我列出 javax.servlet.ServletRequest 的方法时,3.0 API中没有处理异步请求的方法。

public abstract java.lang.String javax.servlet.ServletRequest.getScheme()
public abstract java.lang.String javax.servlet.ServletRequest.getProtocol()
public abstract javax.servlet.ServletInputStream javax.servlet.ServletRequest.getInputStream() throws java.io.IOException
public abstract int javax.servlet.ServletRequest.getContentLength()
public abstract java.lang.Object javax.servlet.ServletRequest.getAttribute(java.lang.String)
public abstract java.lang.String javax.servlet.ServletRequest.getContentType()
public abstract java.util.Locale javax.servlet.ServletRequest.getLocale()
public abstract java.util.Enumeration javax.servlet.ServletRequest.getAttributeNames()
public abstract java.lang.String javax.servlet.ServletRequest.getCharacterEncoding()
public abstract void javax.servlet.ServletRequest.setCharacterEncoding(java.lang.String) throws java.io.UnsupportedEncodingException
public abstract java.lang.String javax.servlet.ServletRequest.getParameter(java.lang.String)
public abstract java.util.Enumeration javax.servlet.ServletRequest.getParameterNames()
public abstract java.lang.String[] javax.servlet.ServletRequest.getParameterValues(java.lang.String)
public abstract java.util.Map javax.servlet.ServletRequest.getParameterMap()
public abstract java.lang.String javax.servlet.ServletRequest.getServerName()
public abstract int javax.servlet.ServletRequest.getServerPort()
public abstract java.io.BufferedReader javax.servlet.ServletRequest.getReader() throws java.io.IOException
public abstract java.lang.String javax.servlet.ServletRequest.getRemoteAddr()
public abstract java.lang.String javax.servlet.ServletRequest.getRemoteHost()
public abstract void javax.servlet.ServletRequest.setAttribute(java.lang.String,java.lang.Object)
public abstract void javax.servlet.ServletRequest.removeAttribute(java.lang.String)
public abstract java.util.Enumeration javax.servlet.ServletRequest.getLocales()
public abstract boolean javax.servlet.ServletRequest.isSecure()
public abstract javax.servlet.RequestDispatcher javax.servlet.ServletRequest.getRequestDispatcher(java.lang.String)
public abstract java.lang.String javax.servlet.ServletRequest.getRealPath(java.lang.String)
public abstract int javax.servlet.ServletRequest.getRemotePort()
public abstract java.lang.String javax.servlet.ServletRequest.getLocalName()
public abstract java.lang.String javax.servlet.ServletRequest.getLocalAddr()
public abstract int javax.servlet.ServletRequest.getLocalPort()

我错过了什么?

1 个答案:

答案 0 :(得分:5)

我假设您以某种方式“管理”引用位于servlet-api之前的类路径中的旧javaee-web-api库(可能是传递性的)。这意味着现有类是从较早的servlet-api中提取的,而较旧规范中不存在的类是从javaee-web-api加载的。

您可以运行mvn dependency:tree来查看引用过时库的位置,然后将其排除。