@Override public void run(Environment environment) { ServiceLocatorUtilities.bind(serviceLocator, new EnvBinder(application, environment)); LifecycleEnvironment lifecycle = environment.lifecycle(); AdminEnvironment admin = environment.admin(); listServices(HealthCheck.class).forEach(healthCheck -> { String name = healthCheck.getClass().getSimpleName(); environment.healthChecks().register(name, healthCheck); }); listServices(Managed.class).forEach(lifecycle::manage); listServices(LifeCycle.class).forEach(lifecycle::manage); listServices(LifeCycle.Listener.class).forEach(lifecycle::addLifeCycleListener); listServices(ServerLifecycleListener.class).forEach(lifecycle::addServerLifecycleListener); listServices(Task.class).forEach(admin::addTask); environment.jersey().register(HK2LifecycleListener.class); //Set service locator as parent for Jersey's service locator environment.getApplicationContext().setAttribute(ServletProperties.SERVICE_LOCATOR, serviceLocator); environment.getAdminContext().setAttribute(ServletProperties.SERVICE_LOCATOR, serviceLocator); serviceLocator.inject(application); }
public AdminEnvironment admin() { return this.environment.admin(); }