本文整理了Java中org.springframework.context.ApplicationContext.getType()
方法的一些代码示例,展示了ApplicationContext.getType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContext.getType()
方法的具体详情如下:
包路径:org.springframework.context.ApplicationContext
类名称:ApplicationContext
方法名:getType
暂无
代码示例来源:origin: shuzheng/zheng
/**
* bean的类型
* @param beanName
* @return
*/
public static Class getType(String beanName) {
return context.getType(beanName);
}
代码示例来源:origin: AxonFramework/AxonFramework
@SuppressWarnings("unchecked")
@Override
public Class<T> getAggregateType() {
if (aggregateType == null) {
aggregateType = (Class<T>) applicationContext.getType(prototypeBeanName);
}
return aggregateType;
}
代码示例来源:origin: wuyouzhuguli/FEBS-Shiro
public static Class<?> getType(String name) {
return applicationContext.getType(name);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Actually register the endpoints. Called by {@link #afterSingletonsInstantiated()}.
*/
protected void registerEndpoints() {
Set<Class<?>> endpointClasses = new LinkedHashSet<>();
if (this.annotatedEndpointClasses != null) {
endpointClasses.addAll(this.annotatedEndpointClasses);
}
ApplicationContext context = getApplicationContext();
if (context != null) {
String[] endpointBeanNames = context.getBeanNamesForAnnotation(ServerEndpoint.class);
for (String beanName : endpointBeanNames) {
endpointClasses.add(context.getType(beanName));
}
}
for (Class<?> endpointClass : endpointClasses) {
registerEndpoint(endpointClass);
}
if (context != null) {
Map<String, ServerEndpointConfig> endpointConfigMap = context.getBeansOfType(ServerEndpointConfig.class);
for (ServerEndpointConfig endpointConfig : endpointConfigMap.values()) {
registerEndpoint(endpointConfig);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine the type of the specified candidate bean and call
* {@link #detectHandlerMethods} if identified as a handler type.
* <p>This implementation avoids bean creation through checking
* {@link org.springframework.beans.factory.BeanFactory#getType}
* and calling {@link #detectHandlerMethods} with the bean name.
* @param beanName the name of the candidate bean
* @since 5.1
* @see #isHandler
* @see #detectHandlerMethods
*/
protected void processCandidateBean(String beanName) {
Class<?> beanType = null;
try {
beanType = obtainApplicationContext().getType(beanName);
}
catch (Throwable ex) {
// An unresolvable bean type, probably from a lazy bean - let's ignore it.
if (logger.isTraceEnabled()) {
logger.trace("Could not resolve type for bean '" + beanName + "'", ex);
}
}
if (beanType != null && isHandler(beanType)) {
detectHandlerMethods(beanName);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Detect if the given handler has any methods that can handle messages and if
* so register it with the extracted mapping information.
* @param handler the handler to check, either an instance of a Spring bean name
*/
protected final void detectHandlerMethods(final Object handler) {
Class<?> handlerType;
if (handler instanceof String) {
ApplicationContext context = getApplicationContext();
Assert.state(context != null, "ApplicationContext is required for resolving handler bean names");
handlerType = context.getType((String) handler);
}
else {
handlerType = handler.getClass();
}
if (handlerType != null) {
final Class<?> userType = ClassUtils.getUserClass(handlerType);
Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
(MethodIntrospector.MetadataLookup<T>) method -> getMappingForMethod(method, userType));
if (logger.isDebugEnabled()) {
logger.debug(methods.size() + " message handler methods found on " + userType + ": " + methods);
}
methods.forEach((key, value) -> registerHandlerMethod(handler, key, value));
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Scan beans in the ApplicationContext, detect and register handler methods.
* @see #isHandler(Class)
* @see #getMappingForMethod(Method, Class)
* @see #handlerMethodsInitialized(Map)
*/
protected void initHandlerMethods() {
String[] beanNames = obtainApplicationContext().getBeanNamesForType(Object.class);
for (String beanName : beanNames) {
if (!beanName.startsWith(SCOPED_TARGET_NAME_PREFIX)) {
Class<?> beanType = null;
try {
beanType = obtainApplicationContext().getType(beanName);
}
catch (Throwable ex) {
// An unresolvable bean type, probably from a lazy bean - let's ignore it.
if (logger.isTraceEnabled()) {
logger.trace("Could not resolve type for bean '" + beanName + "'", ex);
}
}
if (beanType != null && isHandler(beanType)) {
detectHandlerMethods(beanName);
}
}
}
handlerMethodsInitialized(getHandlerMethods());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Look for handler methods in a handler.
* @param handler the bean name of a handler or a handler instance
*/
protected void detectHandlerMethods(final Object handler) {
Class<?> handlerType = (handler instanceof String ?
obtainApplicationContext().getType((String) handler) : handler.getClass());
if (handlerType != null) {
final Class<?> userType = ClassUtils.getUserClass(handlerType);
Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
(MethodIntrospector.MetadataLookup<T>) method -> getMappingForMethod(method, userType));
if (logger.isTraceEnabled()) {
logger.trace(formatMappings(userType, methods));
}
methods.forEach((key, mapping) -> {
Method invocableMethod = AopUtils.selectInvocableMethod(key, userType);
registerHandlerMethod(handler, invocableMethod, mapping);
});
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Look for handler methods in the specified handler bean.
* @param handler either a bean name or an actual handler instance
* @see #getMappingForMethod
*/
protected void detectHandlerMethods(Object handler) {
Class<?> handlerType = (handler instanceof String ?
obtainApplicationContext().getType((String) handler) : handler.getClass());
if (handlerType != null) {
Class<?> userType = ClassUtils.getUserClass(handlerType);
Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
(MethodIntrospector.MetadataLookup<T>) method -> {
try {
return getMappingForMethod(method, userType);
}
catch (Throwable ex) {
throw new IllegalStateException("Invalid mapping on handler class [" +
userType.getName() + "]: " + method, ex);
}
});
if (logger.isTraceEnabled()) {
logger.trace(formatMappings(userType, methods));
}
methods.forEach((method, mapping) -> {
Method invocableMethod = AopUtils.selectInvocableMethod(method, userType);
registerHandlerMethod(handler, invocableMethod, mapping);
});
}
}
代码示例来源:origin: org.springframework/spring-webmvc
/**
* Determine the type of the specified candidate bean and call
* {@link #detectHandlerMethods} if identified as a handler type.
* <p>This implementation avoids bean creation through checking
* {@link org.springframework.beans.factory.BeanFactory#getType}
* and calling {@link #detectHandlerMethods} with the bean name.
* @param beanName the name of the candidate bean
* @since 5.1
* @see #isHandler
* @see #detectHandlerMethods
*/
protected void processCandidateBean(String beanName) {
Class<?> beanType = null;
try {
beanType = obtainApplicationContext().getType(beanName);
}
catch (Throwable ex) {
// An unresolvable bean type, probably from a lazy bean - let's ignore it.
if (logger.isTraceEnabled()) {
logger.trace("Could not resolve type for bean '" + beanName + "'", ex);
}
}
if (beanType != null && isHandler(beanType)) {
detectHandlerMethods(beanName);
}
}
代码示例来源:origin: spring-projects/spring-framework
Class<?> beanType = null;
try {
beanType = context.getType(beanName);
代码示例来源:origin: org.springframework/spring-webmvc
/**
* Look for handler methods in the specified handler bean.
* @param handler either a bean name or an actual handler instance
* @see #getMappingForMethod
*/
protected void detectHandlerMethods(Object handler) {
Class<?> handlerType = (handler instanceof String ?
obtainApplicationContext().getType((String) handler) : handler.getClass());
if (handlerType != null) {
Class<?> userType = ClassUtils.getUserClass(handlerType);
Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
(MethodIntrospector.MetadataLookup<T>) method -> {
try {
return getMappingForMethod(method, userType);
}
catch (Throwable ex) {
throw new IllegalStateException("Invalid mapping on handler class [" +
userType.getName() + "]: " + method, ex);
}
});
if (logger.isTraceEnabled()) {
logger.trace(formatMappings(userType, methods));
}
methods.forEach((method, mapping) -> {
Method invocableMethod = AopUtils.selectInvocableMethod(method, userType);
registerHandlerMethod(handler, invocableMethod, mapping);
});
}
}
代码示例来源:origin: timebusker/spring-boot
public static Class<? extends Object> getType(String name) {
return applicationContext.getType(name);
}
代码示例来源:origin: Nepxion/Discovery
public Class<?> getType(String name) throws NoSuchBeanDefinitionException {
return applicationContext.getType(name);
}
代码示例来源:origin: spring-projects/spring-hateoas
private Iterable<Class<?>> getBeanTypesWithAnnotation(Class<? extends Annotation> type) {
Set<Class<?>> annotatedTypes = new HashSet<>();
for (String beanName : context.getBeanDefinitionNames()) {
Annotation annotation = context.findAnnotationOnBean(beanName, type);
if (annotation != null) {
annotatedTypes.add(context.getType(beanName));
}
}
return annotatedTypes;
}
}
代码示例来源:origin: org.springframework/spring-messaging
/**
* Detect if the given handler has any methods that can handle messages and if
* so register it with the extracted mapping information.
* @param handler the handler to check, either an instance of a Spring bean name
*/
protected final void detectHandlerMethods(final Object handler) {
Class<?> handlerType;
if (handler instanceof String) {
ApplicationContext context = getApplicationContext();
Assert.state(context != null, "ApplicationContext is required for resolving handler bean names");
handlerType = context.getType((String) handler);
}
else {
handlerType = handler.getClass();
}
if (handlerType != null) {
final Class<?> userType = ClassUtils.getUserClass(handlerType);
Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
(MethodIntrospector.MetadataLookup<T>) method -> getMappingForMethod(method, userType));
if (logger.isDebugEnabled()) {
logger.debug(methods.size() + " message handler methods found on " + userType + ": " + methods);
}
methods.forEach((key, value) -> registerHandlerMethod(handler, key, value));
}
}
代码示例来源:origin: org.springframework/spring-messaging
Class<?> beanType = null;
try {
beanType = context.getType(beanName);
代码示例来源:origin: wxyyxc1992/Backend-Boilerplates
@SuppressWarnings("unchecked")
@Override
public Class<? extends Actor> actorClass() {
return (Class<? extends Actor>) applicationContext.getType(actorBeanName);
}
}
代码示例来源:origin: org.beangle.ioc/beangle-ioc-spring
@Override
public Option<Class<?>> getType(Object key) {
try {
Class<?> type = context.getType(key.toString());
if (null == type) return Option.none();
return Option.<Class<?>> some(type);
} catch (NoSuchBeanDefinitionException e) {
return Option.none();
}
}
代码示例来源:origin: ch.rasc/wamp2spring-core
private void detectAnnotatedMethods(String beanName) {
Class<?> handlerType = this.applicationContext.getType(beanName);
final Class<?> userType = ClassUtils.getUserClass(handlerType);
List<EventListenerInfo> eventListeners = detectEventListeners(beanName, userType);
this.subscriptionRegistry.subscribeEventHandlers(eventListeners);
}
内容来源于网络,如有侵权,请联系作者删除!