dependency injection - How to force an embedded Grizzly web application context to start -
i use embedded grizzly web server host restful web-services jersey. working correctly.
my question how force web application context eagerly initialise when start server rather waiting first incoming client request. minor problem, 1 solve.
i start embedded server this:
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 ); } }
the "testbinder" configures dependency injection need , class looks this:
final class testbinder extends abstractbinder { @override protected void configure() { bind(catalogmanager.class).to(catalogmanager.class).in(singleton.class); } }
finally, "catalogmanager" singleton used pre-load , cache of static data application exposes via restful web-services.
the essence of "catalogmanager" this:
public final class catalogmanager { @postconstruct public void initialise() { // load , cache large application data-set here... } }
so problem dependency injection , consequently @postconstruct method not run when server starts up, instead waits until first application request , first user of application gets long delay.
Comments
Post a Comment