当前位置: 首页>>代码示例>>Java>>正文


Java ServiceLocator.getService方法代码示例

本文整理汇总了Java中org.glassfish.hk2.api.ServiceLocator.getService方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceLocator.getService方法的具体用法?Java ServiceLocator.getService怎么用?Java ServiceLocator.getService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.glassfish.hk2.api.ServiceLocator的用法示例。


在下文中一共展示了ServiceLocator.getService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: testGetLoggerWithoutParameters

import org.glassfish.hk2.api.ServiceLocator; //导入方法依赖的package包/类
@Test
public void testGetLoggerWithoutParameters()
{
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            install(loginject(Logger.class, Logger::getAnonymousLogger).as(Binder.class));
            addActiveDescriptor(TestClass.class);
        }
    };
    ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
    TestClass service = serviceLocator.getService(TestClass.class);
    assertNull(service.injectedLogger.getName());
}
 
开发者ID:raner,项目名称:loginject,代码行数:17,代码来源:JavaUtilLoggingLoggerTest.java

示例9: testGetLoggerWithStringParameter

import org.glassfish.hk2.api.ServiceLocator; //导入方法依赖的package包/类
@Test
public void testGetLoggerWithStringParameter()
{
	AbstractBinder binder = new AbstractBinder()
	{
		@Override
		protected void configure()
		{
			install(loginject(Logger.class, Logger::getLogger, currentClassName()).as(Binder.class));
			addActiveDescriptor(TestClass.class);
		}
	};
	ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
	TestClass service = serviceLocator.getService(TestClass.class);
	assertEquals(TestClass.class.getName(), service.injectedLogger.getName());
}
 
开发者ID:raner,项目名称:loginject,代码行数:17,代码来源:JavaUtilLoggingLoggerTest.java

示例10: testGetInferredLoggerWithStringParameter

import org.glassfish.hk2.api.ServiceLocator; //导入方法依赖的package包/类
@Test
public void testGetInferredLoggerWithStringParameter()
{
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            install(loginject(Logger::getLogger, currentClassName()).as(Binder.class));
            addActiveDescriptor(TestClass.class);
        }
    };
    ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
    TestClass service = serviceLocator.getService(TestClass.class);
    assertEquals(TestClass.class.getName(), service.injectedLogger.getName());
}
 
开发者ID:raner,项目名称:loginject,代码行数:17,代码来源:JavaUtilLoggingLoggerTest.java

示例11: testGetLoggerWithClassNameAndBundleNameParameters

import org.glassfish.hk2.api.ServiceLocator; //导入方法依赖的package包/类
@Test
public void testGetLoggerWithClassNameAndBundleNameParameters()
{
    final String bundleName = "ResourceBundle";
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            LogParameter<String> parameter = constantString(bundleName);
            install(loginject(Logger.class, Logger::getLogger, currentClassName(), parameter).as(Binder.class));
            addActiveDescriptor(TestClass.class);
        }
    };
    ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
    TestClass service = serviceLocator.getService(TestClass.class);
    String[] expected = {TestClass.class.getName(), bundleName};
    String[] actual = {service.injectedLogger.getName(), service.injectedLogger.getResourceBundleName()};
    assertArrayEquals(expected, actual);
}
 
开发者ID:raner,项目名称:loginject,代码行数:21,代码来源:JavaUtilLoggingLoggerTest.java

示例12: DashAppConfig

import org.glassfish.hk2.api.ServiceLocator; //导入方法依赖的package包/类
@Inject
    public DashAppConfig(ServiceLocator serviceLocator) {
        logger.info("Registering packages on {}", DashContants.DASH_REST_PACKAGE);
        // Register package for rest endpoints and fasterxml for JSON support
        packages(DashContants.DASH_REST_PACKAGE, DashContants.FASTERXML_PACKAGE);

        logger.info("Building Injectors");
        Injector injector = Guice.createInjector(
                new ConfigurationInjection(),
                new DashGuiceH4ServletModule(),
                new DashH4ServiceInjection(),
                //new DashGuiceH4Module(),
                new JSONInjection()
        );

//        PersistentInit persistenceInit = new PersistentInit();
        PersistenceInit persistenceInit = new PersistenceInit();

        GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
        GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
        guiceBridge.bridgeGuiceInjector(injector);
    }
 
开发者ID:TechnoJays,项目名称:First-Dash-Service,代码行数:23,代码来源:DashAppConfig.java

示例13: ApiConfig

import org.glassfish.hk2.api.ServiceLocator; //导入方法依赖的package包/类
@Inject
public ApiConfig(ServiceLocator serviceLocator) {
  register(JacksonFeature.class);
  register(ValidationFeature.class);
  property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, "true");

  register(AuthenticationRequestFilter.class);
  register(AdminNecessaryRequestFilter.class);
  register(RepositoryControllRequestFilter.class);

  register(HttpCacheControlFilter.class);

  register(ApiForbiddenExceptionMapper.class);
  register(ApiNotFoundExceptionMapper.class);
  register(ApiLoginRequiredExceptionMapper.class);
  register(AjaxValidationErrorExceptionMapper.class);
  register(PostErrorResponseFilter.class);

  GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
  GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
  guiceBridge.bridgeGuiceInjector(GuiceListener.get());

  packages(false, this.getClass().getPackage() + ".rs");
}
 
开发者ID:kamegu,项目名称:git-webapp,代码行数:25,代码来源:ApiConfig.java

示例14: AppConfig

import org.glassfish.hk2.api.ServiceLocator; //导入方法依赖的package包/类
@Inject
public AppConfig(ServiceLocator serviceLocator) {
  register(FreemarkerMvcFeature.class);
  property(FreemarkerMvcFeature.TEMPLATES_BASE_PATH, "/WEB-INF/templates");
  property(FreemarkerMvcFeature.TEMPLATE_OBJECT_FACTORY, FlexibleConfiguration.class);

  register(AttachContextInterceptor.class);
  register(ValidationFeature.class);
  property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, "true");

  register(AuthenticationRequestFilter.class);
  register(AdminNecessaryRequestFilter.class);
  register(RepositoryControllRequestFilter.class);
  register(HtmlLoginRequiredExceptionMapper.class);

  register(HttpCacheControlFilter.class);

  GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
  GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
  guiceBridge.bridgeGuiceInjector(GuiceListener.get());

  packages(false, this.getClass().getPackage() + ".html");
}
 
开发者ID:kamegu,项目名称:git-webapp,代码行数:24,代码来源:AppConfig.java

示例15: contextInitialized

import org.glassfish.hk2.api.ServiceLocator; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent event) {
  ServiceLocator locator = ServiceLocatorUtilities.createAndPopulateServiceLocator();
  ServiceLocatorUtilities.enableImmediateScope(locator);
  Server server = locator.getService(Server.class);

  HttpTransportServer httpTransportServer = new HttpTransportServer().ontransport(server);
  WebSocketTransportServer wsTransportServer = new WebSocketTransportServer().ontransport(server);

  // Installs the server on Atmosphere platform
  ServletContext context = event.getServletContext();
  Servlet servlet = new AsityAtmosphereServlet().onhttp(httpTransportServer).onwebsocket
    (wsTransportServer);
  ServletRegistration.Dynamic reg = context.addServlet(AsityAtmosphereServlet.class.getName(),
    servlet);
  reg.setAsyncSupported(true);
  reg.setInitParameter(ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTOR, Boolean.TRUE.toString());
  reg.addMapping("/cettia");
}
 
开发者ID:cettia,项目名称:cettia-examples,代码行数:20,代码来源:Bootstrap.java


注:本文中的org.glassfish.hk2.api.ServiceLocator.getService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。