當前位置: 首頁>>代碼示例>>Java>>正文


Java ServiceLocator類代碼示例

本文整理匯總了Java中org.glassfish.hk2.api.ServiceLocator的典型用法代碼示例。如果您正苦於以下問題:Java ServiceLocator類的具體用法?Java ServiceLocator怎麽用?Java ServiceLocator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ServiceLocator類屬於org.glassfish.hk2.api包,在下文中一共展示了ServiceLocator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: JerseyApplication

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
@Inject
public JerseyApplication(ServiceLocator serviceLocator) {
	GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
	GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
    guiceBridge.bridgeGuiceInjector(AppLoader.injector);
    
    String disableMoxy = PropertiesHelper.getPropertyNameForRuntime(
    		CommonProperties.MOXY_JSON_FEATURE_DISABLE,
               getConfiguration().getRuntimeType());
       property(disableMoxy, true);
       property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);

       // add the default Jackson exception mappers
       register(JsonParseExceptionMapper.class);
       register(JsonMappingExceptionMapper.class);
       register(JacksonJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
       
       packages(JerseyApplication.class.getPackage().getName());
       
    for (JerseyConfigurator configurator: AppLoader.getExtensions(JerseyConfigurator.class)) {
    	configurator.configure(this);
    }
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:24,代碼來源:JerseyApplication.java

示例2: setUp

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    ServiceLocator locator = ServiceLocatorUtilities.createAndPopulateServiceLocator();
    ServiceLocatorUtilities.bind(locator, new AbstractBinder() {

        @Override
        protected void configure() {
            bind(SecurityService.class).to(SecurityService.class);
            bind(accountDao).to(AccountDao.class);
            bind(passwordDao).to(AccountPasswordDao.class);
            bind(userProvider).to(UserProvider.class);
            bind(event).to(new TypeLiteral<Event<SignedInEvent>>() {
            });
        }
    });
    locator.inject(this);
}
 
開發者ID:backpaper0,項目名稱:sealion,代碼行數:18,代碼來源:SecurityServiceTest.java

示例3: configureGuice

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
private Injector configureGuice(T configuration, Environment environment) throws Exception {
  // setup our core modules...
  appModules.add(new MetricRegistryModule(environment.metrics()));
  appModules.add(new ServletModule());
  // ...and add the app's modules
  appModules.addAll(addModules(configuration, environment));

  final Injector injector = Guice.createInjector(ImmutableList.copyOf(this.appModules));

  // Taken from https://github.com/Squarespace/jersey2-guice/wiki#complex-example. HK2 is no fun.
  JerseyGuiceUtils.install((name, parent) -> {
    if (!name.startsWith("__HK2_Generated_")) {
      return null;
    }

    return injector.createChildInjector(Lists.newArrayList(new JerseyGuiceModule(name)))
        .getInstance(ServiceLocator.class);
  });

  injector.injectMembers(this);
  registerWithInjector(environment, injector);
  return injector;
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:24,代碼來源:GuiceApplication.java

示例4: TestChain

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
public TestChain(TestServiceRunnerBase serviceRunner) {
    this.actions = ImmutableList.of();
    this.serviceLocator = new ServiceLocatorHolder();

    Feature lifecycleListener = new Feature() {
        @Inject
        public void setServiceLocator(ServiceLocator s) {
            serviceLocator.set(s);
        }

        @Override
        public boolean configure(FeatureContext context) {
            return false;
        }
    };
    this.serviceRunner = serviceRunner
            .serviceConfig(serviceRunner.getServiceConfig()
                    .registerInstance(lifecycleListener)
            );
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:21,代碼來源:TestChain.java

示例5: backstopperOnlyExceptionMapperFactory_removes_all_exception_mappers_except_Jersey2ApiExceptionHandler

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
@Test
public void backstopperOnlyExceptionMapperFactory_removes_all_exception_mappers_except_Jersey2ApiExceptionHandler()
    throws NoSuchFieldException, IllegalAccessException {
    // given
    AbstractBinder lotsOfExceptionMappersBinder = new AbstractBinder() {
        @Override
        protected void configure() {
            bind(JsonMappingExceptionMapper.class).to(ExceptionMapper.class).in(Singleton.class);
            bind(JsonParseExceptionMapper.class).to(ExceptionMapper.class).in(Singleton.class);
            bind(generateJerseyApiExceptionHandler(projectApiErrors, utils)).to(ExceptionMapper.class);
        }
    };

    ServiceLocator locator = ServiceLocatorUtilities.bind(lotsOfExceptionMappersBinder);

    // when
    BackstopperOnlyExceptionMapperFactory overrideExceptionMapper = new BackstopperOnlyExceptionMapperFactory(locator);

    // then
    Set<Object> emTypesLeft = overrideExceptionMapper.getFieldObj(
        ExceptionMapperFactory.class, overrideExceptionMapper, "exceptionMapperTypes"
    );
    assertThat(emTypesLeft).hasSize(1);
    ServiceHandle serviceHandle = overrideExceptionMapper.getFieldObj(emTypesLeft.iterator().next(), "mapper");
    assertThat(serviceHandle.getService()).isInstanceOf(Jersey2ApiExceptionHandler.class);
}
 
開發者ID:Nike-Inc,項目名稱:backstopper,代碼行數:27,代碼來源:Jersey2BackstopperConfigHelperTest.java

示例6: bindLocalServices

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
/**
 * Binds local services into a locator. These have to be bound both into our service locator and the Jersey service locator because
 * they do not cross bridge or parent/child boundaries.
 *
 * @param locator
 *     {@code ServiceLocator} into which local services should be installed
 *
 * @return Controller to activate {@link Immediate @Immediate} services
 */
private static ImmediateController bindLocalServices(ServiceLocator locator) {
    // These have to be local because they rely on the InstantiationService, which can only get the Injectee for local injections
    addClasses(locator,
               true,
               CounterFactory.class,
               HistogramFactory.class,
               MeterFactory.class,
               TimerFactory.class,
               AnnotationInterceptionService.class
    );
    if (locator.getServiceHandle(InheritableThreadContext.class) == null) {
        ServiceLocatorUtilities.enableInheritableThreadScope(locator);
    }
    ExtrasUtilities.enableDefaultInterceptorServiceImplementation(locator);
    ExtrasUtilities.enableTopicDistribution(locator);
    if (locator.getServiceHandle(ImmediateController.class) == null) {
        return ServiceLocatorUtilities.enableImmediateScopeSuspended(locator);
    }
    return locator.getService(ImmediateController.class);
}
 
開發者ID:baharclerode,項目名稱:dropwizard-hk2,代碼行數:30,代碼來源:HK2Bundle.java

示例7: constructorWithServiceLocatorReturnsGivenServiceLocatorAndSetsConfigContextAndResourceConfig

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
@Test
public void constructorWithServiceLocatorReturnsGivenServiceLocatorAndSetsConfigContextAndResourceConfig() {
    ServiceLocator serviceLocator = getMockServiceLocator();

    JerseyApplication<JerseyConfigSection> application =
            new JerseyApplicationBase<JerseyConfigSection>(serviceLocator) { };

    assertThat(application.serviceLocator()).isEqualTo(serviceLocator);
    assertThat(application.configContext()).isEqualTo(configContext);

    assertThat(application.resourceConfig()).isEqualTo(resourceConfig);

    ApplicationResolver applicationResolverFromServiceLocator = application.serviceLocator()
            .getService(ApplicationResolver.class);

    assertThat(applicationResolverFromServiceLocator.application()).isEqualTo(application);
}
 
開發者ID:joeyb,項目名稱:undercarriage,代碼行數:18,代碼來源:JerseyApplicationBaseTests.java

示例8: configure

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
@Override
public boolean configure(FeatureContext context) {
	InjectionManager injectionManager = InjectionManagerProvider.getInjectionManager(context);
	ServiceLocator locator;
	if (injectionManager instanceof ImmediateHk2InjectionManager) {
		locator = ((ImmediateHk2InjectionManager) injectionManager).getServiceLocator();
	} else if (injectionManager instanceof DelayedHk2InjectionManager) {
		locator = ((DelayedHk2InjectionManager) injectionManager).getServiceLocator();
	} else {
		throw new IllegalStateException("expected an hk2 injection manager");
	}
	GuiceBridge.getGuiceBridge().initializeGuiceBridge(locator);
	// register all your modules, here
	Injector injector = Guice.createInjector(new GreetingModule());
	GuiceIntoHK2Bridge guiceBridge = locator.getService(GuiceIntoHK2Bridge.class);
	guiceBridge.bridgeGuiceInjector(injector);
	return true;
}
 
開發者ID:bbilger,項目名稱:jrestless-examples,代碼行數:19,代碼來源:GuiceFeature.java

示例9: VelocityViewProcessor

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
@Inject
public VelocityViewProcessor(final javax.ws.rs.core.Configuration config, final ServiceLocator serviceLocator,
                             @Optional final ServletContext servletContext) {
    super(config, servletContext, "velocity", "vm");

    this.factory = getTemplateObjectFactory(serviceLocator, VelocityConfigurationFactory.class,
            new Value<VelocityConfigurationFactory>() {
                @Override
                public VelocityConfigurationFactory get() {
                    Configuration configuration = getTemplateObjectFactory(serviceLocator, Configuration.class,
                            Values.<Configuration>empty());
                    if (configuration == null) {
                        return new VelocityDefaultConfigurationFactory(servletContext);
                    } else {
                        return new VelocitySuppliedConfigurationFactory(configuration);
                    }
                }
            });
    Velocity.init();
}
 
開發者ID:Feng-Zihao,項目名稱:jersey-mvc-velocity,代碼行數:21,代碼來源:VelocityViewProcessor.java

示例10: FreemarkerViewProcessor

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
/**
 * Create an instance of this processor with injected {@link javax.ws.rs.core.Configuration config} and
 * (optional) {@link javax.servlet.ServletContext servlet context}.
 *
 * @param config         config to configure this processor from.
 * @param serviceLocator service locator to initialize template object factory if needed.
 * @param servletContext (optional) servlet context to obtain template resources from.
 */
@Inject
public FreemarkerViewProcessor(final javax.ws.rs.core.Configuration config, final ServiceLocator serviceLocator,
                               @Optional final ServletContext servletContext) {
    super(config, servletContext, "freemarker", getSupportedExtensions(config, servletContext));

    this.factory = getTemplateObjectFactory(serviceLocator, FreemarkerConfigurationFactory.class,
            new Value<FreemarkerConfigurationFactory>() {
                @Override
                public FreemarkerConfigurationFactory get() {
                    Configuration configuration = getTemplateObjectFactory(serviceLocator, Configuration.class,
                            Values.<Configuration>empty());
                    if (configuration == null) {
                        return new FreemarkerDefaultConfigurationFactory(servletContext);
                    } else {
                        return new FreemarkerSuppliedConfigurationFactory(configuration);
                    }
                }
            });

}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:29,代碼來源:FreemarkerViewProcessor.java

示例11: setupWithModule

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
protected static void setupWithModule(Module baseModule) {
  Log.debug("Setting up Jersey");

  application = new TestApplication();
  Log.trace("+- application=[{}]", application);

  Log.debug("Bootstrapping Jersey2-Guice bridge");
  ServiceLocator locator = BootstrapUtils.newServiceLocator();
  Log.trace("+- locator=[{}]", locator);

  final List<Module> modules = Arrays.asList(new ServletModule(), baseModule);
  final Injector injector = BootstrapUtils.newInjector(locator, modules);
  Log.trace("+- injector=[{}]", injector);

  BootstrapUtils.install(locator);
  Log.trace("+- done: locator installed");
}
 
開發者ID:HuygensING,項目名稱:antioch,代碼行數:18,代碼來源:EndpointTest.java

示例12: Application

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
@Inject
public Application(ServiceLocator serviceLocator) {

       //Since Jersey doesn't support Guice, setup a bridge so that Guice will work
	GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
	GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
	
	guiceBridge.bridgeGuiceInjector(Main.injector);

       //Gets Jackson all squared away with Jersey
	register(Jackson1Feature.class);
	register(DefaultObjectMapperProvider.class);

       //Register apis and other Jersey things here
       register(TestApi.class);
       register(TestExceptionMapper.class);
}
 
開發者ID:tommyschnabel,項目名稱:SimpleJavaServer,代碼行數:18,代碼來源:Application.java

示例13: MyApplication

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
@Inject
public MyApplication(ServiceLocator serviceLocator) {
    packages(Resource.class.getPackage().getName()); // todo: try class

    // todo: test!

    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override
        protected void configure() {
            bind(Service.class);
        }
    });

    // todo: auth intercept (will not work with Guice - make dual mapping or use jersey interceptors or try jersey2-guice)

    GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);

    GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
    guiceBridge.bridgeGuiceInjector(injector);
}
 
開發者ID:nhekfqn,項目名稱:jersey2-guice-embedded-jetty-poc,代碼行數:21,代碼來源:MyApplication.java

示例14: testLog4J

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
@Test
public void testLog4J()
{
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            install(loginject(Logger.class, LogManager::getLogger, currentClass()).as(Binder.class));
            addActiveDescriptor(TestClass.class);
        }
    };
    ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
    TestClass service = serviceLocator.getService(TestClass.class);
    assertEquals(TestClass.class.getName(), service.logger.getName());
}
 
開發者ID:raner,項目名稱:loginject,代碼行數:17,代碼來源:LogInjectLog4JTest.java

示例15: testInferredLog4J

import org.glassfish.hk2.api.ServiceLocator; //導入依賴的package包/類
@Test
public void testInferredLog4J()
{
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            install(loginject(LogManager::getLogger, currentClass()).as(Binder.class));
            addActiveDescriptor(TestClass.class);
        }
    };
    ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
    TestClass service = serviceLocator.getService(TestClass.class);
    assertEquals(TestClass.class.getName(), service.logger.getName());
}
 
開發者ID:raner,項目名稱:loginject,代碼行數:17,代碼來源:LogInjectLog4JTest.java


注:本文中的org.glassfish.hk2.api.ServiceLocator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。