无法在名称为“ spring”的servlet中解析名称为“ streamrecords”的视图

Ankur Soni:

我正在使用Spring 4,Java 8,Tomcat 7的控制器示例中的一个简单的流整数值

码:

package com.entrib.emg.server.controller.rest;
import java.io.IOException;
import java.io.OutputStream;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

@Controller
public class StreamRecordsController {

    @RequestMapping(value = "/streamrecords", method = RequestMethod.GET)
    public StreamingResponseBody handleRequest ()
            throws Exception {

        return new StreamingResponseBody() {
            @Override
            public void writeTo (OutputStream out) throws IOException {
                for (int i = 0; i < 1000; i++) {
                    out.write((Integer.toString(i) + " - ")
                                        .getBytes());
                    out.flush();
                    try {
                        Thread.sleep(5);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
    }
}

错误:

Type Exception Report

Message Could not resolve view with name 'streamrecords' in servlet with name 'spring'

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

javax.servlet.ServletException: Could not resolve view with name 'streamrecords' in servlet with name 'spring'
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1266)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Note The full stack trace of the root cause is available in the server logs.

以下是快照:

在此处输入图片说明

题:

我在这里想念什么。

期望:

这只是一个简单的rest API代码,我期望从浏览器或邮递员访问该API时,都会从此控制器流式传输整数。

------------------------------------------------

更新

------------------------------------------------

当我添加时@ResponseBody,我将遇到错误,

Type Status Report

Description The target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request, and the server is unwilling to supply a default representation.
帕维尔:

您在Servlet方法上缺少@ResponseBody,或者可以使用@RestController标记您的类

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Java,Spring,Apache Tiles错误:无法在名称为“ dispatcher”的servlet中解析名称为“ index”的视图

Spring Mvc Java无法在名称为'dispatcher'的servlet中解析名称为'home'的视图

无法在名称为“ dispatcherServlet”的servlet中解析名称为“ forward:/index.html”的视图

无法解析名称为Y的servlet中名称为X的视图

ils。无法在名称为“ grailsDispatcherServlet”的servlet中解析名称为“ index”的视图

无法在名称为'grailsDispatcherServlet'的servlet中解析名称为'/ hello / index'的视图

在Spring Boot中无法解析名称为'index'的视图

javax.servlet.ServletException:无法解析名称为“NA-dispatcher”的servlet中名称为“login”的视图

Spring Security抛出javax.servlet.ServletException:无法解析名称为'j_spring_security_check'的视图

EnableWebMvc引发ServletException:无法解析名称为的视图

在Linux中无法复制名称为“ $”的文件

找不到名称为“ ARTShape”的视图组件

无法更新名称为“ routing”的列

Spring Cloud Kubernetes:无法读取名称为configMap的内容

Spring:无法在Spring MVC中解析视图名称

无法从Redshift读取名称为空格的列中的数据

如何在名称为会话变量的视图上显示图像?

Spring无法解析servlet中的视图

名称为appServlet-servlet.xml的问题

由于“无法导航到名称为...的路线”而无法导航

名称为空的文件

IntelliJ问题->无法创建名称为“ Main”的类

“ NSInternalInconsistencyException”,原因:“无法在捆绑包中加载NIB:...”,名称为

无法找到名称为 [默认] [Modules\Brokerquotes\Entities\Insuree] 的工厂

PreconditionViolationException:无法加载名称为testing.ConnectionTest的类

Laravel 5.2:无法找到名称为[default]的工厂

jQuery无法隐藏输入名称为“ style”的表单?

Angular HttpClient,名称为'query'的参数无法设置

无法修复名称为“ springSecurityFilterChain”的bean创建错误