编程语言
首页 > 编程语言> > java – 缺少servlet api 3.0 jar中的异步方法?

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

作者:互联网

我正在开发一个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>

有趣的是,导入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()

我错过了什么?

解决方法:

我假设你以某种方式“管理”引用了一个旧的servlet-api库(可能是传递的),它位于javaee-web-api之前的类路径中.这意味着现有的类是从旧的servlet-api中获取的,而旧版本中不存在的类是从javaee-web-api加载的.

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

标签:java,asynchronous,servlet-3-0
来源: https://codeday.me/bug/20190620/1244457.html