Home > Back-end >  Ask, if I want to use in static blocks of code inside a dao class of automatic injection, how to do?
Ask, if I want to use in static blocks of code inside a dao class of automatic injection, how to do?

Time:02-20

A class start time is not the first to perform static block of code?
Is what I want now before I start this class to perform static code block, through the automatic injection of the dao to query the database load data (because I don't want to frequently check, the management said that don't use redis), if direct
The @autowired
Private static HolidayDao HolidayDao;
This way, in the static block of code will be null pointer inside, how to use this dao in static code block to query a data

CodePudding user response:

 @ Resource 
Private KpzMapper KpzMapper;
Private static KpzMapper tl;
//in a static method call Mapper update database
@ PostConstruct
Public void init () {
Tl=kpzMapper;
}

In the tl to call a method that