I want to implement a feature in which at deploy time, I should load list of objects from Database. The database already have respective implementaiton done which is being used on the fly.
Given that I am new to Spring, I am trying to understand different features of spring which i can leverage to implement this feature. If i wasn't using Spring, I would have
- Created a Thread-Safe Singleton Class
- Load that class at application load time by servlet life-cycle
- Load everything in that Singleton Class and override existing db class to check this singleton class before issuing query. This way a query will be issued only if this class hasn't loaded for some reason.
Now, In spring, I am so confuse. I have been reaidng different articles and trying to find some pointers. First of all, shall i use @Component
to make the class singleton ? Would spring take care of thread safety?
Secondly, Would this class be a Service
class for spring ? Do i have to annotate it with @Service
?
Third, shall i use @PostConstruct
to load this class at startup ? Or there are other better options ?