consistent loading of optional classes
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1926 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
ab6805521b
commit
e8a9ef9bcf
|
|
@ -132,6 +132,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
|||
ClassLoader cl = AutowiredAnnotationBeanPostProcessor.class.getClassLoader();
|
||||
try {
|
||||
this.autowiredAnnotationTypes.add((Class<? extends Annotation>) cl.loadClass("javax.inject.Inject"));
|
||||
logger.info("JSR-330 'javax.inject.Inject' annotation found and supported for autowiring");
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// JSR-330 API not available - simply skip.
|
||||
|
|
|
|||
|
|
@ -93,6 +93,19 @@ import org.springframework.util.StringUtils;
|
|||
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory
|
||||
implements ConfigurableListableBeanFactory, BeanDefinitionRegistry, Serializable {
|
||||
|
||||
private static Class javaxInjectProviderClass = null;
|
||||
|
||||
static {
|
||||
ClassLoader cl = DefaultListableBeanFactory.class.getClassLoader();
|
||||
try {
|
||||
javaxInjectProviderClass = cl.loadClass("javax.inject.Provider");
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// JSR-330 API not available - Provider interface simply not supported then.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Map from serialized id to factory instance */
|
||||
private static final Map<String, Reference<DefaultListableBeanFactory>> serializableFactories =
|
||||
new ConcurrentHashMap<String, Reference<DefaultListableBeanFactory>>();
|
||||
|
|
@ -646,7 +659,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
|||
if (descriptor.getDependencyType().equals(ObjectFactory.class)) {
|
||||
return new DependencyObjectFactory(descriptor, beanName);
|
||||
}
|
||||
else if (descriptor.getDependencyType().getName().equals("javax.inject.Provider")) {
|
||||
else if (descriptor.getDependencyType().equals(javaxInjectProviderClass)) {
|
||||
return new DependencyProviderFactory().createDependencyProvider(descriptor, beanName);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -140,16 +140,15 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
|||
private static Class<? extends Annotation> ejbRefClass = null;
|
||||
|
||||
static {
|
||||
ClassLoader cl = CommonAnnotationBeanPostProcessor.class.getClassLoader();
|
||||
try {
|
||||
webServiceRefClass = ClassUtils.forName("javax.xml.ws.WebServiceRef",
|
||||
CommonAnnotationBeanPostProcessor.class.getClassLoader());
|
||||
webServiceRefClass = (Class) cl.loadClass("javax.xml.ws.WebServiceRef");
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
webServiceRefClass = null;
|
||||
}
|
||||
try {
|
||||
ejbRefClass = ClassUtils.forName("javax.ejb.EJB",
|
||||
CommonAnnotationBeanPostProcessor.class.getClassLoader());
|
||||
ejbRefClass = (Class) cl.loadClass("javax.ejb.EJB");
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
ejbRefClass = null;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
|
|||
import org.springframework.core.task.AsyncTaskExecutor;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Advisor that activates asynchronous method execution through the {@link Async}
|
||||
|
|
@ -73,9 +72,9 @@ public class AsyncAnnotationAdvisor extends AbstractPointcutAdvisor {
|
|||
public AsyncAnnotationAdvisor(Executor executor) {
|
||||
Set<Class<? extends Annotation>> asyncAnnotationTypes = new LinkedHashSet<Class<? extends Annotation>>(2);
|
||||
asyncAnnotationTypes.add(Async.class);
|
||||
ClassLoader cl = AsyncAnnotationAdvisor.class.getClassLoader();
|
||||
try {
|
||||
asyncAnnotationTypes.add(ClassUtils.forName(
|
||||
"javax.ejb.Asynchronous", AsyncAnnotationAdvisor.class.getClassLoader()));
|
||||
asyncAnnotationTypes.add((Class) cl.loadClass("javax.ejb.Asynchronous"));
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// If EJB 3.1 API not present, simply ignore.
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import java.util.TreeSet;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||
|
||||
/**
|
||||
|
|
@ -52,13 +51,9 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
|
|||
*/
|
||||
public abstract class CollectionFactory {
|
||||
|
||||
private static final String NAVIGABLE_SET_CLASS_NAME = "java.util.NavigableSet";
|
||||
private static Class navigableSetClass = null;
|
||||
|
||||
private static final String NAVIGABLE_MAP_CLASS_NAME = "java.util.NavigableMap";
|
||||
|
||||
private static Class navigableSet = null;
|
||||
|
||||
private static Class navigableMap = null;
|
||||
private static Class navigableMapClass = null;
|
||||
|
||||
private static final Set<Class> approximableCollectionTypes = new HashSet<Class>(10);
|
||||
|
||||
|
|
@ -75,11 +70,12 @@ public abstract class CollectionFactory {
|
|||
approximableMapTypes.add(SortedMap.class);
|
||||
|
||||
// New Java 6 collection interfaces
|
||||
ClassLoader cl = CollectionFactory.class.getClassLoader();
|
||||
try {
|
||||
navigableSet = ClassUtils.forName(NAVIGABLE_SET_CLASS_NAME, CollectionFactory.class.getClassLoader());
|
||||
navigableMap = ClassUtils.forName(NAVIGABLE_MAP_CLASS_NAME, CollectionFactory.class.getClassLoader());
|
||||
approximableCollectionTypes.add(navigableSet);
|
||||
approximableMapTypes.add(navigableMap);
|
||||
navigableSetClass = cl.loadClass("java.util.NavigableSet");
|
||||
navigableMapClass = cl.loadClass("java.util.NavigableMap");
|
||||
approximableCollectionTypes.add(navigableSetClass);
|
||||
approximableMapTypes.add(navigableMapClass);
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// not running on Java 6 or above...
|
||||
|
|
@ -240,7 +236,7 @@ public abstract class CollectionFactory {
|
|||
if (List.class.equals(collectionType)) {
|
||||
return new ArrayList(initialCapacity);
|
||||
}
|
||||
else if (SortedSet.class.equals(collectionType) || collectionType.equals(navigableSet)) {
|
||||
else if (SortedSet.class.equals(collectionType) || collectionType.equals(navigableSetClass)) {
|
||||
return new TreeSet();
|
||||
}
|
||||
else if (Set.class.equals(collectionType) || Collection.class.equals(collectionType)) {
|
||||
|
|
@ -307,7 +303,7 @@ public abstract class CollectionFactory {
|
|||
if (Map.class.equals(mapType)) {
|
||||
return new LinkedHashMap(initialCapacity);
|
||||
}
|
||||
else if (SortedMap.class.equals(mapType) || mapType.equals(navigableMap)) {
|
||||
else if (SortedMap.class.equals(mapType) || mapType.equals(navigableMapClass)) {
|
||||
return new TreeMap();
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue