本文整理匯總了Java中com.google.inject.Injector.getExistingBinding方法的典型用法代碼示例。如果您正苦於以下問題:Java Injector.getExistingBinding方法的具體用法?Java Injector.getExistingBinding怎麽用?Java Injector.getExistingBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.inject.Injector
的用法示例。
在下文中一共展示了Injector.getExistingBinding方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getBean
import com.google.inject.Injector; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> T getBean(String beanId)
{
Injector injector = ensureInjector();
Key<Object> nameKey = Key.get(Object.class, Names.named(beanId));
Binding<Object> binding = injector.getExistingBinding(nameKey);
if( binding != null )
{
return (T) binding.getProvider().get();
}
ClassLoader classLoader = privatePluginService.getClassLoader(pluginId);
try
{
Class<?> clazz = classLoader.loadClass(beanId);
return (T) injector.getInstance(clazz);
}
catch( ClassNotFoundException e )
{
throw new RuntimeException(e);
}
}
示例2: getBeanForType
import com.google.inject.Injector; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> T getBeanForType(Class<T> type)
{
Injector injector = ensureInjector();
Binding<?> binding = injector.getExistingBinding(Key.get(type));
if( binding != null )
{
return (T) binding.getProvider().get();
}
return null;
}
示例3: getBeanForKey
import com.google.inject.Injector; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public <T> T getBeanForKey(Key<T> key)
{
Injector injector = ensureInjector();
Binding<T> binding = injector.getExistingBinding(key);
if( binding == null )
{
binding = (Binding<T>) injector.getExistingBinding(key.ofType(key.getTypeLiteral().getRawType()));
}
if( binding != null )
{
return binding.getProvider().get();
}
return null;
}