【问题标题】:Handling StreamingBodyResponse on client using thymeleaf使用 thymeleaf 在客户端处理 StreamingBodyResponse
【发布时间】:2017-01-04 06:02:38
【问题描述】:

我使用的是 Spring Boot 4.2。我有一个返回 StreamingBodyResponse (控制台输出)的服务。我想在视图中显示这个输出(最好是百里香,但一切都很好。)现在它只是打开一个浏览器并在那里流式传输它。我想做的是在百里香视图的文本区域中显示流响应和关闭此视图也不应该影响流式传输以在服务器端停止和崩溃。如果有人能指出我正确的方向,那就太好了。

 @PostMapping(value="/environment",produces =MediaType.TEXT_PLAIN)
public StreamingResponseBody environmentSubmit(@ModelAttribute Environment environment) {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    String currentUserName = authentication.getName();
    Configuration configuration = Configuration.createFromPostParams(
            environment.getDriver(),
            environment.getVersion(),
            currentUserName);
    StreamingResponseBody response =executor.execute(configuration);
    return response;

【问题讨论】:

    标签: java spring spring-mvc client thymeleaf


    【解决方案1】:

    您可以尝试以下方法以确保它异步运行并且不会超时:

    @Configuration
    public static class WebConfig extends WebMvcConfigurerAdapter {
    
        @Override
        public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
            configurer.setDefaultTimeout(-1);
            configurer.setTaskExecutor(asyncTaskExecutor());
        }
    
        @Bean
        public AsyncTaskExecutor asyncTaskExecutor() {
            return new SimpleAsyncTaskExecutor("async");
        }
    
    }
    

    External source with same code

    【讨论】:

      猜你喜欢
      • 2014-01-16
      • 2018-04-17
      • 2018-10-02
      • 1970-01-01
      • 2013-09-28
      • 1970-01-01
      • 1970-01-01
      • 2016-09-20
      • 2018-10-07
      相关资源
      最近更新 更多