[英]java.lang.IllegalStateException: getOutputStream() has already been called for this response
[英]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()
。
我在内存数据库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;
}
}
和测试班
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());
}
}
主班
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());
}
}
尝试访问上面抛出异常的数据http:// localhost:8080 / books / 978-1-78528-415-1
这不是一个理想的解决方案,但是在向映射的子项添加了渴望的获取类型(即fetch=FetchType.EAGER
)之后,我能够使我的工作正常
@ManyToMany (fetch=FetchType.EAGER)
private List<Reviewer> reviewers;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.