Possibly duplicate of Servlet not loading on startup, however Im not allowed yet to comment, so I have to start a new question for this...
Same setting, having a servlet using Jersey and Tomcat, using load-on-startup for loading the container. However, due to the thread mentioned above, I understand that this only load the Jersey container but not the classes I setup for the servlet.
So, related to what is implied in the answer of the thread above, how is it done that not only the contained is loaded at startup but also my classes which are annotated with @Path (which will e.g. load data from a DB in memory).
@Singleton
@Path( "156846986" )
public class SearchEngine {
@Inject
private DatabaseService dbService;
@Inject
private PatriciaTrieEngine trieEngine;
}
and for example:
@Singleton
@Path( "3455470640" )
public class PatriciaTrieEngine {
@Inject
DatabaseService dbService;
private PatriciaTrie< Object > patriciaTrie;
@PostConstruct
public void init( ) throws SQLException {
...some code initializing the trie by loading data from a database u using dbService
}
}
finally some classes like SearchService
have the endpoints for requests:
@Path( "/search" )
@Produces( "application/json" )
public class SearchService {
@Inject
private DatabaseService dbService;
@Inject
private SearchEngine engine;
@GET
@Path( "/candidates" )
public Response getCandidates(@QueryParam( "query" ) final String input) throws UnsupportedEncodingException {
use Patricia trie via SearchEngine in order to find candidates for given query
return Response.ok().entity( candidates ).build();
}
}
Ultimately it is the PatriciaTrie which should be loaded at startup as it takes several minutes to load the data into the trie.