當我嘗試在Spring Data Repository方法上使用@Async時,出現以下錯誤:如何使彈簧數據@Async工作?錯誤:PersistentEntity不能爲空
{「cause」:null,「message」:「PersistentEntity must not null! 「}
彷彿它嘗試序列CompletableFuture <>。
的倉庫代碼:
@Query("SELECT p FROM Produto p where descricao LIKE CONCAT(UPPER(:like),'%')")
@Async
CompletableFuture<List<Produto>> findByLikeAsync(@Param("like") String like);
配置:
@SpringBootApplication
@EntityScan(basePackages = {"..."})
@EnableJpaRepositories(basePackages = {"..."})
@EnableAsync
@Configuration
public class Application implements AsyncConfigurer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(7);
executor.setMaxPoolSize(42);
executor.setQueueCapacity(11);
executor.setThreadNamePrefix("MyExecutor-");
executor.initialize();
return executor;
}
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new CustomAsyncExceptionHandler();
}
}
我曾嘗試使用未來<>而不是CompletableFuture <>,但它拋出了同樣的錯誤。
任何想法?
謝謝。
爲什麼「持久性實體不能爲空」讓你覺得它試圖序列化'CompletableFuture'? stacktrace應該告訴你* real *錯誤在哪裏。 – Kayaman