Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在计划任务上未检索到与存储库的关联OneToMany_Java_Hibernate_Spring Boot_Scheduled Tasks - Fatal编程技术网

Java 在计划任务上未检索到与存储库的关联OneToMany

Java 在计划任务上未检索到与存储库的关联OneToMany,java,hibernate,spring-boot,scheduled-tasks,Java,Hibernate,Spring Boot,Scheduled Tasks,我在一个服务中,有一个预定的任务,我想从数据库中获取一个对象。它具有急切的关联,因此find方法应该完全获得它 @Service public class CustomTask { @Autowired CustomRepository customRepository; @Scheduled(fixedRate = 1000) public void action() { customRepository.find(1); } }

我在一个服务中,有一个预定的任务,我想从数据库中获取一个对象。它具有急切的关联,因此find方法应该完全获得它

@Service
public class CustomTask {

    @Autowired
    CustomRepository customRepository;

    @Scheduled(fixedRate = 1000)
    public void action() {
         customRepository.find(1);
    }
}
但在这里它不起作用。关联为
null

在Spring引导控制器中,repository方法可以完美地工作


你知道我可以用这种预定的服务方法获取整个对象吗?

在应用程序开始时调用预定任务,此时环境可能尚未完全初始化

通过任务的初始延迟,我可以访问整个对象:

@Scheduled(initialDelay=10000, fixedRate = 1000)
注意:这与其说是修复,不如说是一种变通方法