Spring-boot中servlet异步摄错
来源:1-8 异步非阻塞 Servlet 代码示例

Amy楠
2019-04-30
@WebServlet(urlPatterns = "/my/servlet",
asyncSupported = true)
public class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
AsyncContext asyncContext = req.getAsyncContext();
asyncContext.start(()->{
try {
resp.getWriter().println("helloWorld");
} catch (IOException e) {
e.printStackTrace();
}
asyncContext.complete();
});
}
}
There was an unexpected error (type=Internal Server Error, status=500).
It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
写回答
1回答
-
Amy楠
提问者
2019-04-30
好吧,我自己写错了,
AsyncContext asyncContext = req.startAsync();
00
相似问题