Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to force an embedded Grizzly web application context to start
    text
    copied!<p>I use an embedded Grizzly web server to host RESTful web-services with Jersey. This is all working correctly.</p> <p>My question is how to force the web application context to eagerly initialise when I start the server rather than waiting for the first incoming client request. This is a minor problem, but one I would like to solve.</p> <p>I start the embedded server like this:</p> <pre><code>public final class TestApplication { public TestApplication() throws Exception { HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer( "http://0.0.0.0:8888", new ResourceConfig() .registerInstances( new TestBinder(), ) .registerClasses( JacksonJsonProvider.class, ) .packages( AbstractResource.class.getPackage().getName() ), true ); } } </code></pre> <p>The "TestBinder" configures the dependency injection that I need and that class looks like this:</p> <pre><code>final class TestBinder extends AbstractBinder { @Override protected void configure() { bind(CatalogManager.class).to(CatalogManager.class).in(Singleton.class); } } </code></pre> <p>Finally, "CatalogManager" is a singleton that is used to pre-load and cache all of the static data that my application exposes via the RESTful web-services.</p> <p>The essence of "CatalogManager" is this:</p> <pre><code>public final class CatalogManager { @PostConstruct public void initialise() { // Load and cache a large application data-set here... } } </code></pre> <p>So the problem is that the dependency injection and consequently the @PostConstruct method do not run when the server starts up, instead it waits until the first application request and the first user of my application gets a long delay.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload