This may be a theoretical question rather than a code question.
I started work on a spring webMVC REST API. I have a very specific requirement. I have some file system resource ( text file, markdown file). I want to read those resources and kept them in memory for faster access ( The number of resources are small so I can keep them in memory). I will planning to implement some watch event mechanism if any files changes than reload the resources.
- My Question is what is the best way in spring to achieve this ( By this I mean read resources during application context start ). I want to define The configuration object as a bean which would be passed to REST controllers.
I was reading the spring docs and I am thinking about implementing this as singleton configuration bean and pass that bean to all controllers. Whenever file system changes I have to reload the bean. Is this a good solution?
- There are so many possible options to initialize something during application context start this SO question has plenty of answers and I can adopt any solution, But I want to know what would be the best approach considering my specific requirement.
The solution should be easily scalable and modular in nature.