2

I am trying to do the following:

public static List<String> skills;

@Autowired
private static ISkillsDao skillsDao; // ISKillsDao is a crudrepository (Interface)

static{
updateSkills();
}

public static void updateSkills(){
    skills = skillsDao.getSkills(); //This will return all the skills from db
}

@Autowired //as the object is static
public void setSkillsDao(ISkillsDao skillsDao){
ClassName.skillsDao = skillsDao;
}

Basically I want to load all the skills from db in a static list. But my static "Interface Crudrepository" object (skillsDao) is not getting autowired. The same works for a class but not for an interface. Also, if there is any better way to do this then kindly letme know.

Asha
  • 67
  • 9
  • Is the class a component? Can you show us the code declaring the class? – Blagoj Atanasovski Dec 03 '18 at 13:58
  • Yes the class is a component. Following is the code : @Component public class Utils { ....code.. } – Asha Dec 03 '18 at 14:01
  • If you want to load it once at Startup, better use initializing bean https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/factory/InitializingBean.html – Jens Dec 03 '18 at 14:02
  • @Jens can you share some code or give an example? – Asha Dec 03 '18 at 14:04

0 Answers0