简体   繁体   English

Spring Boot Web应用程序:引发java.lang.IllegalStateException:此响应已调用getOutputStream()

[英]Spring Boot Web Application: throwing java.lang.IllegalStateException: getOutputStream() has already been called for this response

In Spring Boot Web Application throwing java.lang.IllegalStateException: getOutputStream() has already been called for this response. 在Spring Boot Web应用程序中,抛出java.lang.IllegalStateException: getOutputStream()此响应已经调用java.lang.IllegalStateException: getOutputStream()

I have in memory database h2 with ORM Relation of @ManyToOne, @ManyToMany, my class look like 我在内存数据库h2具有@ManyToOne, @ManyToMany, ORM关系@ManyToOne, @ManyToMany,我的课程看起来像

@Entity
public class Book {
    @Id
    @GeneratedValue
    private Long id;
    private String isbn;
    private String title;
    private String description;
    @ManyToOne
    private Author author;
    @ManyToOne
    private Publisher publisher;
    @ManyToMany
    private List<Reviewer> reviewers;

    protected Book() {
    }

    public Book(String isbn, String title, Author author, Publisher publisher) {
        this.isbn = isbn;
        this.title = title;
        this.author = author;
        this.publisher = publisher;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getIsbn() {
        return isbn;
    }

    public void setIsbn(String isbn) {
        this.isbn = isbn;
    }

    public String getTitle() {
        return title;
    }
}

and testing class 和测试班

public class StartupRunner implements CommandLineRunner {
    protected final Log logger = LogFactory.getLog(getClass());

    @Autowired
    private BookRepository bookRepository;

    @Autowired
    private AuthorRepository authorRepository;

    @Autowired
    private PublisherRepository publisherRepository;

    @Override
    public void run(String... args) throws Exception {
        logger.info("Number of books: " + bookRepository.count());
        Author author = new Author("Alex", "Antonov");
        author = authorRepository.save(author);
        Publisher publisher = new Publisher("Packt");
        publisher = publisherRepository.save(publisher);
        Book book = new Book("978-1-78528-415-1", "Spring Boot Recipes", author, publisher);
        bookRepository.save(book);
    }

    @Scheduled(initialDelay = 1000, fixedRate = 10000)
    public void run() {

        logger.info("Number of books: " + bookRepository.count());
    }

}

main class 主班

public class StartupRunner implements CommandLineRunner {
    protected final Log logger = LogFactory.getLog(getClass());

    @Autowired
    private BookRepository bookRepository;

    @Autowired
    private AuthorRepository authorRepository;

    @Autowired
    private PublisherRepository publisherRepository;

    @Override
    public void run(String... args) throws Exception {
        logger.info("Number of books: " + bookRepository.count());
        Author author = new Author("Alex", "Antonov");
        author = authorRepository.save(author);
        Publisher publisher = new Publisher("Packt");
        publisher = publisherRepository.save(publisher);
        Book book = new Book("978-1-78528-415-1", "Spring Boot Recipes", author, publisher);
        bookRepository.save(book);
    }

    @Scheduled(initialDelay = 1000, fixedRate = 10000)
    public void run() {

        logger.info("Number of books: " + bookRepository.count());
    }

}

Trying to access the data http://localhost:8080/books/978-1-78528-415-1 throwing above exception 尝试访问上面抛出异常的数据http:// localhost:8080 / books / 978-1-78528-415-1

Not an ideal solution but I was able to get mine working after adding an eager fetch type to the mapped children (ie fetch=FetchType.EAGER ) 这不是一个理想的解决方案,但是在向映射的子项添加了渴望的获取类型(即fetch=FetchType.EAGER )之后,我能够使我的工作正常

@ManyToMany (fetch=FetchType.EAGER)
private List<Reviewer> reviewers;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalStateException:已经为此响应调用了 getOutputStream() - java.lang.IllegalStateException: getOutputStream() has already been called for this response java.lang.IllegalStateException:已为此响应调用了getOutputStream() - java.lang.IllegalStateException: getOutputStream() has already been called for this response Spring:java.lang.IllegalStateException:已经为此响应调用了getOutputStream() - Spring: java.lang.IllegalStateException: getOutputStream() has already been called for this response 原因:java.lang.IllegalStateException:此响应已经调用了getOutputStream()。 - Caused by: java.lang.IllegalStateException: getOutputStream() has already been called for this response org.apache.jasper.JasperException:java.lang.IllegalStateException:此响应已调用getOutputStream() - org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response REST-java.lang.IllegalStateException:此响应已调用getOutputStream() - REST - java.lang.IllegalStateException: getOutputStream() has already been called for this response java.lang.IllegalStateException:此响应已经被调用getOutputStream()-SpringBoot - java.lang.IllegalStateException: getOutputStream() has already been called for this response - SpringBoot 我得到一个异常:java.lang.IllegalStateException:已经为此响应调用了getOutputStream() - I am getting an exception: java.lang.IllegalStateException: getOutputStream() has already been called for this response 我正在获取java.lang.IllegalStateException:此响应已调用getOutputStream()异常 - I m getting java.lang.IllegalStateException: getOutputStream() has already been called for this response Exception java.lang.IllegalStateException:已为此响应调用getWriter() - java.lang.IllegalStateException: getWriter() has already been called for this response
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM