I'm asking for elements that have a recursive relationship in one table:
child id | parent id
1 | null
2 | 1
3 | 1
4 | 2
And so on...To ask for this whole datastructure it takes about 10 secondsAt the moment I can't redesign this table because it cost too much time (for more information: Spring Repository performance issues with recursive ORM Class)
Now, I am thinking about preloading all data during spring startup in a bean, so that the client "communicates" with the bean and I update the data in bean and database. I think it doesn't matter how long this startup takes, but it matters how long the user has to wait for its answer.
So far, I didn't manage it to preload it. I was trying to create a bean like this:
public class AppConfig extends WebMvcConfigurerAdapter {
...
@Autowired
SkillDAO skillDAO
...
@Bean(name="allSkills")
public List<Skill> allSkills(){
return skillDAO.findBySkill(null);
}
...
It doesn't work cause I get an error:
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dataSource': Requested bean is currently in creation: Is there an unresolvable circular reference?
By the way, I create all my beans in AppConfig. When I delete this "allSkills" bean, it works again.
UPDATE
@Component
public class MyListener {
@Autowired
private SkillDAO skillDAO;
@EventListener
public void onApplicationReady(ApplicationReadyEvent ready) {
System.out.println("++++++++++++++ HALLO +++++++++++++");
skillDAO.findBySkill(null);
}
}
...
@Bean(name="skillBean")
public MyListener myListener() {
return new MyListener();
}