亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring Boot - 查詢方法公共抽象 java.util.stream.Stream

Spring Boot - 查詢方法公共抽象 java.util.stream.Stream

墨色風雨 2021-11-11 16:00:45
我需要流式傳輸對象列表,但是當我使用 JpaRepository 和 @Query 嘗試它時,我收到此異常:Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'MainApplication': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'MyServiceImpl': Unsatisfied dependency expressed through field 'myDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyDAO': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.stream.Stream com.my.package.dao.MyDAO.streamAll()!MyDAO 代碼:@Repositorypublic interface MyDAO extends JpaRepository<MyEntity, Long> {    @QueryHints(value = @QueryHint(name = HINT_FETCH_SIZE, value = "" +         Integer.MIN_VALUE))    @Query(value = "SELECT m FROM MyEntity m")    Stream<MyEntity> streamAll();    ...}主要代碼:@SpringBootApplication@ComponentScan("com.my.package.*")@EntityScan("com.my.package.*")@Configuration@EnableAutoConfigurationpublic class MainApplication implements CommandLineRunner {    @Autowired    MyServiceInterface service;    public static void main(String[] args) {        SpringApplication.run(MainApplication.class, args);    }    @Override    public void run(String... args) throws Exception {        try {            service.createCsv();        } catch (RuntimeException e) {            System.out.println(e);        }    }}我已經嘗試了一切,但沒有任何效果,請幫助我!
查看完整描述

2 回答

?
森林海

TA貢獻2011條經驗 獲得超2個贊

您將無法使用,Stream<MyEntity> findAll();因為JpaRepository已經定義了具有List返回類型的方法,因此您可以像這樣重命名方法Stream<MyEntity> getAll();或使用 Ordering 將方法重命名為Stream<MyEntity> findAllByOrderByIdAsc();.


查看完整回答
反對 回復 2021-11-11
?
拉丁的傳說

TA貢獻1789條經驗 獲得超8個贊

只需刪除

@Query(value = "SELECT m FROM MyEntity m")

并使用 JPARepository 的 findAll() 方法,如下所示

Stream<MyEntity> findAll();


查看完整回答
反對 回復 2021-11-11
  • 2 回答
  • 0 關注
  • 187 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號