DATACMNS-341 - RepositoryFactory(Bean)Support is now class loader aware.
Let both RepositoryFactorySupport and RepositoryFactoryBeanSupport implement BeanClassLoaderAware to pick up the ClassLoader used by the container. The latter class forwards the configured instance into the factory it creates.
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.data.repository.core.support;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Required;
|
||||
@@ -41,7 +42,7 @@ import org.springframework.util.Assert;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>, S, ID extends Serializable> implements
|
||||
InitializingBean, RepositoryFactoryInformation<S, ID>, FactoryBean<T> {
|
||||
InitializingBean, RepositoryFactoryInformation<S, ID>, FactoryBean<T>, BeanClassLoaderAware {
|
||||
|
||||
private RepositoryFactorySupport factory;
|
||||
|
||||
@@ -50,6 +51,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
|
||||
private Object customImplementation;
|
||||
private NamedQueries namedQueries;
|
||||
private MappingContext<?, ?> mappingContext;
|
||||
private ClassLoader classLoader;
|
||||
|
||||
/**
|
||||
* Setter to inject the repository interface to implement.
|
||||
@@ -69,7 +71,6 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
|
||||
* @param queryLookupStrategyKey
|
||||
*/
|
||||
public void setQueryLookupStrategyKey(Key queryLookupStrategyKey) {
|
||||
|
||||
this.queryLookupStrategyKey = queryLookupStrategyKey;
|
||||
}
|
||||
|
||||
@@ -79,7 +80,6 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
|
||||
* @param customImplementation
|
||||
*/
|
||||
public void setCustomImplementation(Object customImplementation) {
|
||||
|
||||
this.customImplementation = customImplementation;
|
||||
}
|
||||
|
||||
@@ -102,6 +102,15 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
|
||||
this.mappingContext = mappingContext;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.BeanClassLoaderAware#setBeanClassLoader(java.lang.ClassLoader)
|
||||
*/
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.core.support.RepositoryFactoryInformation#getEntityInformation()
|
||||
@@ -179,6 +188,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
|
||||
this.factory = createRepositoryFactory();
|
||||
this.factory.setQueryLookupStrategyKey(queryLookupStrategyKey);
|
||||
this.factory.setNamedQueries(namedQueries);
|
||||
this.factory.setBeanClassLoader(classLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.EntityInformation;
|
||||
@@ -47,12 +48,13 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public abstract class RepositoryFactorySupport {
|
||||
public abstract class RepositoryFactorySupport implements BeanClassLoaderAware {
|
||||
|
||||
private final List<RepositoryProxyPostProcessor> postProcessors = new ArrayList<RepositoryProxyPostProcessor>();
|
||||
private QueryLookupStrategy.Key queryLookupStrategyKey;
|
||||
private List<QueryCreationListener<?>> queryPostProcessors = new ArrayList<QueryCreationListener<?>>();
|
||||
private NamedQueries namedQueries = PropertiesBasedNamedQueries.EMPTY;
|
||||
private ClassLoader classLoader = org.springframework.util.ClassUtils.getDefaultClassLoader();
|
||||
|
||||
private QueryCollectingQueryCreationListener collectingListener = new QueryCollectingQueryCreationListener();
|
||||
|
||||
@@ -78,6 +80,15 @@ public abstract class RepositoryFactorySupport {
|
||||
this.namedQueries = namedQueries == null ? PropertiesBasedNamedQueries.EMPTY : namedQueries;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.BeanClassLoaderAware#setBeanClassLoader(java.lang.ClassLoader)
|
||||
*/
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.classLoader = classLoader == null ? org.springframework.util.ClassUtils.getDefaultClassLoader() : classLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a {@link QueryCreationListener} to the factory to plug in functionality triggered right after creation of
|
||||
* {@link RepositoryQuery} instances.
|
||||
@@ -146,7 +157,7 @@ public abstract class RepositoryFactorySupport {
|
||||
|
||||
result.addAdvice(new QueryExecutorMethodInterceptor(information, customImplementation, target));
|
||||
|
||||
return (T) result.getProxy();
|
||||
return (T) result.getProxy(classLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user