Cache TypeExcludeFilter delegates
Cache TypeExcludeFilter delegates to save repeated calls to `beanFactory.getBeansOfType`. Closes gh-17595
This commit is contained in:
parent
ff9f5fd1c7
commit
ca5df3cc9c
|
@ -51,6 +51,8 @@ public class TypeExcludeFilter implements TypeFilter, BeanFactoryAware {
|
||||||
|
|
||||||
private BeanFactory beanFactory;
|
private BeanFactory beanFactory;
|
||||||
|
|
||||||
|
private Collection<TypeExcludeFilter> delegates;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||||
this.beanFactory = beanFactory;
|
this.beanFactory = beanFactory;
|
||||||
|
@ -60,9 +62,7 @@ public class TypeExcludeFilter implements TypeFilter, BeanFactoryAware {
|
||||||
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
|
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (this.beanFactory instanceof ListableBeanFactory && getClass() == TypeExcludeFilter.class) {
|
if (this.beanFactory instanceof ListableBeanFactory && getClass() == TypeExcludeFilter.class) {
|
||||||
Collection<TypeExcludeFilter> delegates = ((ListableBeanFactory) this.beanFactory)
|
for (TypeExcludeFilter delegate : getDelegates()) {
|
||||||
.getBeansOfType(TypeExcludeFilter.class).values();
|
|
||||||
for (TypeExcludeFilter delegate : delegates) {
|
|
||||||
if (delegate.match(metadataReader, metadataReaderFactory)) {
|
if (delegate.match(metadataReader, metadataReaderFactory)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,15 @@ public class TypeExcludeFilter implements TypeFilter, BeanFactoryAware {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Collection<TypeExcludeFilter> getDelegates() {
|
||||||
|
Collection<TypeExcludeFilter> delegates = this.delegates;
|
||||||
|
if (delegates == null) {
|
||||||
|
delegates = ((ListableBeanFactory) this.beanFactory).getBeansOfType(TypeExcludeFilter.class).values();
|
||||||
|
this.delegates = delegates;
|
||||||
|
}
|
||||||
|
return delegates;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
throw new IllegalStateException("TypeExcludeFilter " + getClass() + " has not implemented equals");
|
throw new IllegalStateException("TypeExcludeFilter " + getClass() + " has not implemented equals");
|
||||||
|
|
Loading…
Reference in New Issue