This will certainly work. Just be careful how to use any singleton that you do not abuse it. Read the answer to this question , explaining why ApplicationContext rarely (though sometimes) uses the appropriate context.
In addition, having an ApplicationContext available everywhere allows you to be more careless about how you organize your classes, since you wonβt need to think about what functionality the ApplicationContext really needs, and whether you should take this into account, etc. It is just possible, depending on how disciplined you are.
I am always very careful in singles, although other famous people do not agree, but I think it is still quite widely discussed whether singletones are a pattern or an anti-pattern. If you use the singleton and Google anti-pattern, you will find articles like this that, in my opinion, make some good points.
source share