Spring: Singleton that should be loaded initialized at startup
<p>I have a Spring (Boot) application that does some heavy NLP text processing. I'm looking for a way to optimize performance by loading some models upfront and only once.</p>

<h2>Scenario</h2>

<p>There is a <code>@Service</code> that consists of several methods to analyse a text (e.g. extract keywords). Pre-trained models will be loaded by the NLP framework I use in my service, which takes a lot of time and memory. The models can be re-used so there is no need to load them every time. The most efficient way would be to load them once and keep them in memory. You can also assume that the models are Thread-safe.</p>

<h2>Question</h2>

<p>What is the best way to define a singleton and initialize it once at startup?</p>

<p>For now I use <code>@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)</code> on my service but there is no guarantee that the service will be initialized at startup as far as I understood. I also experimented with <code>@Configuration</code> but didn't find a solution.</p>