本文整理了Java中io.micronaut.inject.qualifiers.Qualifiers.byName
方法的一些代码示例,展示了Qualifiers.byName
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Qualifiers.byName
方法的具体详情如下:
包路径:io.micronaut.inject.qualifiers.Qualifiers
类名称:Qualifiers
方法名:byName
[英]Build a qualifier for the given name.
[中]为给定的名称构建一个限定符。
代码示例来源:origin: micronaut-projects/micronaut-core
private ClientVersioningConfiguration getVersioningConfiguration(AnnotationValue<Client> clientAnnotation) {
return versioningConfigurations.computeIfAbsent(getClientId(clientAnnotation), clientId ->
beanContext.findBean(ClientVersioningConfiguration.class, Qualifiers.byName(clientId))
.orElseGet(() -> beanContext.findBean(ClientVersioningConfiguration.class, Qualifiers.byName(ClientVersioningConfiguration.DEFAULT))
.orElseThrow(() -> new ConfigurationException("Attempt to apply a '@Version' to the request, but " +
"versioning configuration found neither for '" + clientId + "' nor '" + ClientVersioningConfiguration.DEFAULT + "' provided.")
)));
}
代码示例来源:origin: micronaut-projects/micronaut-core
private NioEventLoopGroup newEventLoopGroup(NettyHttpServerConfiguration.EventLoopConfig config) {
if (config != null) {
Optional<ExecutorService> executorService = config.getExecutorName().flatMap(name -> beanLocator.findBean(ExecutorService.class, Qualifiers.byName(name)));
NioEventLoopGroup group = executorService.map(service ->
new NioEventLoopGroup(config.getNumOfThreads(), service)
).orElseGet(() -> {
if (threadFactory != null) {
return new NioEventLoopGroup(config.getNumOfThreads(), threadFactory);
} else {
return new NioEventLoopGroup(config.getNumOfThreads());
}
});
config.getIoRatio().ifPresent(group::setIoRatio);
return group;
} else {
if (threadFactory != null) {
return new NioEventLoopGroup(NettyThreadFactory.DEFAULT_EVENT_LOOP_THREADS, threadFactory);
} else {
return new NioEventLoopGroup();
}
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
this.executionHandle = beanContext.findExecutionHandle(
beanType,
Qualifiers.byName(beanQualifier),
beanMethod,
argumentTypes != null ? argumentTypes : method.getArgumentTypes()
代码示例来源:origin: micronaut-projects/micronaut-core
HttpClient clientBean = beanContext.findBean(HttpClient.class, Qualifiers.byName(clientId)).orElse(null);
if (null != clientBean) {
return clientBean;
Optional<HttpClientConfiguration> clientSpecificConfig = beanContext.findBean(
HttpClientConfiguration.class,
Qualifiers.byName(clientId)
);
Class<HttpClientConfiguration> defaultConfiguration = clientAnn.get("configuration", Class.class).orElse(HttpClientConfiguration.class);
new JsonMediaTypeCodec(objectMapper,
beanContext.getBean(ApplicationConfiguration.class),
beanContext.findBean(CodecConfiguration.class, Qualifiers.byName(JsonMediaTypeCodec.CONFIGURATION_QUALIFIER)).orElse(null))));
代码示例来源:origin: micronaut-projects/micronaut-core
HttpClient existingBean = beanContext.findBean(HttpClient.class, Qualifiers.byName(value)).orElse(null);
if (existingBean != null) {
return existingBean;
代码示例来源:origin: micronaut-projects/micronaut-core
int argCount = requiredArguments.length;
Object result;
Qualifier<Object> qualifier = Qualifiers.byName(functionName);
Class<Object> functionType = method.getDeclaringType();
BeanDefinition<Object> beanDefinition = applicationContext.getBeanDefinition(functionType, qualifier);
代码示例来源:origin: micronaut-projects/micronaut-spring
@Override
public void registerSingleton(String beanName, Object singletonObject) {
final Class type = singletonObject.getClass();
beanContext.registerSingleton(
type,
singletonObject,
Qualifiers.byName(beanName)
);
super.registerSingleton(beanName, singletonObject);
}
代码示例来源:origin: io.micronaut/micronaut-inject
/**
* Build a qualifier for the given annotation.
*
* @param annotation The annotation
* @param <T> The component type
* @return The qualifier
*/
public static <T> Qualifier<T> byAnnotation(Annotation annotation) {
if (annotation.annotationType() == Type.class) {
Type typeAnn = (Type) annotation;
return byType(typeAnn.value());
} else if (annotation.annotationType() == Named.class) {
Named nameAnn = (Named) annotation;
return byName(nameAnn.value());
} else {
return new AnnotationQualifier<>(annotation);
}
}
代码示例来源:origin: io.micronaut/inject
/**
* Build a qualifier for the given annotation.
*
* @param annotation The annotation
* @param <T> The component type
* @return The qualifier
*/
public static <T> Qualifier<T> byAnnotation(Annotation annotation) {
if (annotation.annotationType() == Type.class) {
Type typeAnn = (Type) annotation;
return byType(typeAnn.value());
} else if (annotation.annotationType() == Named.class) {
Named nameAnn = (Named) annotation;
return byName(nameAnn.value());
} else {
return new AnnotationQualifier<>(annotation);
}
}
代码示例来源:origin: io.micronaut/micronaut-spring
private PlatformTransactionManager resolveTransactionManager(String transactionManagerName) {
try {
if (transactionManagerName != null) {
return this.transactionManagerMap.computeIfAbsent(transactionManagerName, s ->
beanLocator.getBean(PlatformTransactionManager.class, Qualifiers.byName(transactionManagerName))
);
} else {
return this.transactionManagerMap.computeIfAbsent("default", s ->
beanLocator.getBean(PlatformTransactionManager.class)
);
}
} catch (NoSuchBeanException e) {
throw new TransactionSystemException("No transaction manager configured" + (transactionManagerName != null ? " for name: " + transactionManagerName : ""));
}
}
}
代码示例来源:origin: io.micronaut/spring
private PlatformTransactionManager resolveTransactionManager(String transactionManagerName) {
try {
if (transactionManagerName != null) {
return this.transactionManagerMap.computeIfAbsent(transactionManagerName, s ->
beanLocator.getBean(PlatformTransactionManager.class, Qualifiers.byName(transactionManagerName))
);
} else {
return this.transactionManagerMap.computeIfAbsent("default", s ->
beanLocator.getBean(PlatformTransactionManager.class)
);
}
} catch (NoSuchBeanException e) {
throw new TransactionSystemException("No transaction manager configured" + (transactionManagerName != null ? " for name: " + transactionManagerName : ""));
}
}
}
代码示例来源:origin: io.micronaut/runtime
@SuppressWarnings("unchecked")
private Weigher<Object, Object> findWeigher() {
return applicationContext.findBean(Weigher.class, Qualifiers.byName(cacheConfiguration.getCacheName()))
.orElseGet(() -> applicationContext.findBean(Weigher.class)
.orElse(Weigher.singletonWeigher()));
}
}
代码示例来源:origin: io.micronaut/inject
/**
* <p>Build a qualifier for the given annotation. This qualifier will match a candidate under the following
* circumstances:</p>
*
* <ul>
* <li>If the <tt>type</tt> parameter is {@link Named} then the value of the {@link Named} annotation within the metadata is used to match the candidate by name</li>
* <li>If the <tt>type</tt> parameter is {@link Type} then the value of the {@link Type} annotation is used to match the candidate by type</li>
* </ul>
*
* @param metadata The metadata
* @param type The annotation type
* @param <T> The component type
* @return The qualifier
*/
public static <T> Qualifier<T> byAnnotation(AnnotationMetadata metadata, String type) {
if (Type.class.getName().equals(type)) {
Optional<Class> aClass = metadata.classValue(type);
if (aClass.isPresent()) {
return byType(aClass.get());
}
} else if (Named.class.getName().equals(type)) {
Optional<String> value = metadata.getValue(type, String.class);
if (value.isPresent()) {
return byName(value.get());
}
}
return new AnnotationMetadataQualifier<>(metadata, type);
}
代码示例来源:origin: io.micronaut/micronaut-inject
/**
* <p>Build a qualifier for the given annotation. This qualifier will match a candidate under the following
* circumstances:</p>
*
* <ul>
* <li>If the <tt>type</tt> parameter is {@link Named} then the value of the {@link Named} annotation within the metadata is used to match the candidate by name</li>
* <li>If the <tt>type</tt> parameter is {@link Type} then the value of the {@link Type} annotation is used to match the candidate by type</li>
* </ul>
*
* @param metadata The metadata
* @param type The annotation type
* @param <T> The component type
* @return The qualifier
*/
public static <T> Qualifier<T> byAnnotation(AnnotationMetadata metadata, String type) {
if (Type.class.getName().equals(type)) {
Optional<Class> aClass = metadata.classValue(type);
if (aClass.isPresent()) {
return byType(aClass.get());
}
} else if (Named.class.getName().equals(type)) {
Optional<String> value = metadata.getValue(type, String.class);
if (value.isPresent()) {
return byName(value.get());
}
}
return new AnnotationMetadataQualifier<>(metadata, type);
}
代码示例来源:origin: io.micronaut/inject
/**
* Build a qualifier for the given annotation.
*
* @param metadata The metadata
* @param type The annotation type
* @param <T> The component type
* @return The qualifier
*/
public static <T> Qualifier<T> byAnnotation(AnnotationMetadata metadata, Class<? extends Annotation> type) {
if (Type.class == type) {
Optional<Class> aClass = metadata.classValue(type);
if (aClass.isPresent()) {
return byType(aClass.get());
}
} else if (Named.class == type) {
Optional<String> value = metadata.getValue(type, String.class);
if (value.isPresent()) {
return byName(value.get());
}
}
return new AnnotationMetadataQualifier<>(metadata, type);
}
代码示例来源:origin: io.micronaut/micronaut-inject
/**
* Build a qualifier for the given annotation.
*
* @param metadata The metadata
* @param type The annotation type
* @param <T> The component type
* @return The qualifier
*/
public static <T> Qualifier<T> byAnnotation(AnnotationMetadata metadata, Class<? extends Annotation> type) {
if (Type.class == type) {
Optional<Class> aClass = metadata.classValue(type);
if (aClass.isPresent()) {
return byType(aClass.get());
}
} else if (Named.class == type) {
Optional<String> value = metadata.getValue(type, String.class);
if (value.isPresent()) {
return byName(value.get());
}
}
return new AnnotationMetadataQualifier<>(metadata, type);
}
代码示例来源:origin: io.micronaut/aop
this.executionHandle = beanContext.findExecutionHandle(
beanType,
Qualifiers.byName(beanQualifier),
beanMethod,
method.getArgumentTypes()
代码示例来源:origin: io.micronaut/micronaut-aop
this.executionHandle = beanContext.findExecutionHandle(
beanType,
Qualifiers.byName(beanQualifier),
beanMethod,
argumentTypes != null ? argumentTypes : method.getArgumentTypes()
代码示例来源:origin: micronaut-projects/micronaut-spring
@Override
public @Nonnull
<T> T getBean(@Nonnull String name, @Nonnull Class<T> requiredType) throws BeansException {
ArgumentUtils.requireNonNull("requiredType", requiredType);
if (beanExcludes.contains(requiredType)) {
throw new NoSuchBeanDefinitionException(requiredType);
}
try {
if (isAlias(name)) {
final String[] aliases = getAliases(name);
for (String alias : aliases) {
if (super.containsSingleton(alias)) {
return super.getBean(alias, requiredType);
}
}
}
if (super.containsSingleton(name)) {
final Object o = super.getBean(name);
if (requiredType.isInstance(o)) {
return (T) o;
}
}
return beanContext.getBean(requiredType, Qualifiers.byName(name));
} catch (NoSuchBeanException e) {
throw new NoSuchBeanDefinitionException(requiredType, e.getMessage());
} catch (Exception e) {
throw new BeanCreationException(name, e.getMessage(), e);
}
}
代码示例来源:origin: io.micronaut.aws/micronaut-function-aws-api-proxy
@Override
public void initialize() throws ContainerInitializationException {
Timer.start(TIMER_INIT);
try {
this.applicationContext = applicationContextBuilder.environments(Environment.FUNCTION)
.build()
.start();
this.lambdaContainerEnvironment.setApplicationContext(applicationContext);
this.lambdaContainerEnvironment.setJsonCodec(applicationContext.getBean(JsonMediaTypeCodec.class));
this.lambdaContainerEnvironment.setRouter(applicationContext.getBean(Router.class));
this.executorService = applicationContext.getBean(ExecutorService.class, Qualifiers.byName(TaskExecutors.IO));
this.requestArgumentSatisfier = new RequestArgumentSatisfier(
applicationContext.getBean(RequestBinderRegistry.class)
);
} catch (Exception e) {
throw new ContainerInitializationException(
"Error starting Micronaut container: " + e.getMessage(),
e
);
}
Timer.stop(TIMER_INIT);
}
内容来源于网络,如有侵权,请联系作者删除!