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();
|
ClassLoader cl = AutowiredAnnotationBeanPostProcessor.class.getClassLoader();
|
||||||
try {
|
try {
|
||||||
this.autowiredAnnotationTypes.add((Class<? extends Annotation>) cl.loadClass("javax.inject.Inject"));
|
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) {
|
catch (ClassNotFoundException ex) {
|
||||||
// JSR-330 API not available - simply skip.
|
// JSR-330 API not available - simply skip.
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,19 @@ import org.springframework.util.StringUtils;
|
||||||
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory
|
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory
|
||||||
implements ConfigurableListableBeanFactory, BeanDefinitionRegistry, Serializable {
|
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 */
|
/** Map from serialized id to factory instance */
|
||||||
private static final Map<String, Reference<DefaultListableBeanFactory>> serializableFactories =
|
private static final Map<String, Reference<DefaultListableBeanFactory>> serializableFactories =
|
||||||
new ConcurrentHashMap<String, Reference<DefaultListableBeanFactory>>();
|
new ConcurrentHashMap<String, Reference<DefaultListableBeanFactory>>();
|
||||||
|
|
@ -646,7 +659,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||||
if (descriptor.getDependencyType().equals(ObjectFactory.class)) {
|
if (descriptor.getDependencyType().equals(ObjectFactory.class)) {
|
||||||
return new DependencyObjectFactory(descriptor, beanName);
|
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);
|
return new DependencyProviderFactory().createDependencyProvider(descriptor, beanName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -140,16 +140,15 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
||||||
private static Class<? extends Annotation> ejbRefClass = null;
|
private static Class<? extends Annotation> ejbRefClass = null;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
ClassLoader cl = CommonAnnotationBeanPostProcessor.class.getClassLoader();
|
||||||
try {
|
try {
|
||||||
webServiceRefClass = ClassUtils.forName("javax.xml.ws.WebServiceRef",
|
webServiceRefClass = (Class) cl.loadClass("javax.xml.ws.WebServiceRef");
|
||||||
CommonAnnotationBeanPostProcessor.class.getClassLoader());
|
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException ex) {
|
catch (ClassNotFoundException ex) {
|
||||||
webServiceRefClass = null;
|
webServiceRefClass = null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ejbRefClass = ClassUtils.forName("javax.ejb.EJB",
|
ejbRefClass = (Class) cl.loadClass("javax.ejb.EJB");
|
||||||
CommonAnnotationBeanPostProcessor.class.getClassLoader());
|
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException ex) {
|
catch (ClassNotFoundException ex) {
|
||||||
ejbRefClass = null;
|
ejbRefClass = null;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
|
||||||
import org.springframework.core.task.AsyncTaskExecutor;
|
import org.springframework.core.task.AsyncTaskExecutor;
|
||||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Advisor that activates asynchronous method execution through the {@link Async}
|
* Advisor that activates asynchronous method execution through the {@link Async}
|
||||||
|
|
@ -73,9 +72,9 @@ public class AsyncAnnotationAdvisor extends AbstractPointcutAdvisor {
|
||||||
public AsyncAnnotationAdvisor(Executor executor) {
|
public AsyncAnnotationAdvisor(Executor executor) {
|
||||||
Set<Class<? extends Annotation>> asyncAnnotationTypes = new LinkedHashSet<Class<? extends Annotation>>(2);
|
Set<Class<? extends Annotation>> asyncAnnotationTypes = new LinkedHashSet<Class<? extends Annotation>>(2);
|
||||||
asyncAnnotationTypes.add(Async.class);
|
asyncAnnotationTypes.add(Async.class);
|
||||||
|
ClassLoader cl = AsyncAnnotationAdvisor.class.getClassLoader();
|
||||||
try {
|
try {
|
||||||
asyncAnnotationTypes.add(ClassUtils.forName(
|
asyncAnnotationTypes.add((Class) cl.loadClass("javax.ejb.Asynchronous"));
|
||||||
"javax.ejb.Asynchronous", AsyncAnnotationAdvisor.class.getClassLoader()));
|
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException ex) {
|
catch (ClassNotFoundException ex) {
|
||||||
// If EJB 3.1 API not present, simply ignore.
|
// 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.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -52,13 +51,9 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||||
*/
|
*/
|
||||||
public abstract class CollectionFactory {
|
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 navigableMapClass = null;
|
||||||
|
|
||||||
private static Class navigableSet = null;
|
|
||||||
|
|
||||||
private static Class navigableMap = null;
|
|
||||||
|
|
||||||
private static final Set<Class> approximableCollectionTypes = new HashSet<Class>(10);
|
private static final Set<Class> approximableCollectionTypes = new HashSet<Class>(10);
|
||||||
|
|
||||||
|
|
@ -75,11 +70,12 @@ public abstract class CollectionFactory {
|
||||||
approximableMapTypes.add(SortedMap.class);
|
approximableMapTypes.add(SortedMap.class);
|
||||||
|
|
||||||
// New Java 6 collection interfaces
|
// New Java 6 collection interfaces
|
||||||
|
ClassLoader cl = CollectionFactory.class.getClassLoader();
|
||||||
try {
|
try {
|
||||||
navigableSet = ClassUtils.forName(NAVIGABLE_SET_CLASS_NAME, CollectionFactory.class.getClassLoader());
|
navigableSetClass = cl.loadClass("java.util.NavigableSet");
|
||||||
navigableMap = ClassUtils.forName(NAVIGABLE_MAP_CLASS_NAME, CollectionFactory.class.getClassLoader());
|
navigableMapClass = cl.loadClass("java.util.NavigableMap");
|
||||||
approximableCollectionTypes.add(navigableSet);
|
approximableCollectionTypes.add(navigableSetClass);
|
||||||
approximableMapTypes.add(navigableMap);
|
approximableMapTypes.add(navigableMapClass);
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException ex) {
|
catch (ClassNotFoundException ex) {
|
||||||
// not running on Java 6 or above...
|
// not running on Java 6 or above...
|
||||||
|
|
@ -240,7 +236,7 @@ public abstract class CollectionFactory {
|
||||||
if (List.class.equals(collectionType)) {
|
if (List.class.equals(collectionType)) {
|
||||||
return new ArrayList(initialCapacity);
|
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();
|
return new TreeSet();
|
||||||
}
|
}
|
||||||
else if (Set.class.equals(collectionType) || Collection.class.equals(collectionType)) {
|
else if (Set.class.equals(collectionType) || Collection.class.equals(collectionType)) {
|
||||||
|
|
@ -307,7 +303,7 @@ public abstract class CollectionFactory {
|
||||||
if (Map.class.equals(mapType)) {
|
if (Map.class.equals(mapType)) {
|
||||||
return new LinkedHashMap(initialCapacity);
|
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();
|
return new TreeMap();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue