ResolvableType-based type matching at the BeanFactory API level
Issue: SPR-12147
This commit is contained in:
@@ -47,13 +47,13 @@ import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.context.PayloadApplicationEvent;
|
||||
import org.springframework.context.HierarchicalMessageSource;
|
||||
import org.springframework.context.LifecycleProcessor;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.MessageSourceAware;
|
||||
import org.springframework.context.MessageSourceResolvable;
|
||||
import org.springframework.context.NoSuchMessageException;
|
||||
import org.springframework.context.PayloadApplicationEvent;
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
import org.springframework.context.event.ApplicationEventMulticaster;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
@@ -1024,6 +1024,12 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||
return getBeanFactory().isPrototype(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTypeMatch(String name, ResolvableType targetType) throws NoSuchBeanDefinitionException {
|
||||
assertBeanFactoryActive();
|
||||
return getBeanFactory().isTypeMatch(name, targetType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTypeMatch(String name, Class<?> targetType) throws NoSuchBeanDefinitionException {
|
||||
assertBeanFactoryActive();
|
||||
@@ -1061,6 +1067,12 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||
return getBeanFactory().getBeanDefinitionNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getBeanNamesForType(ResolvableType type) {
|
||||
assertBeanFactoryActive();
|
||||
return getBeanFactory().getBeanNamesForType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getBeanNamesForType(Class<?> type) {
|
||||
assertBeanFactoryActive();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.jndi.JndiLocatorSupport;
|
||||
import org.springframework.jndi.TypeMismatchNamingException;
|
||||
|
||||
@@ -172,6 +173,12 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
|
||||
return !this.shareableResources.contains(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTypeMatch(String name, ResolvableType targetType) throws NoSuchBeanDefinitionException {
|
||||
Class<?> type = getType(name);
|
||||
return (targetType == null || (type != null && targetType.isAssignableFrom(type)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTypeMatch(String name, Class<?> targetType) throws NoSuchBeanDefinitionException {
|
||||
Class<?> type = getType(name);
|
||||
|
||||
Reference in New Issue
Block a user