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 Collection<TypeExcludeFilter> delegates;
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
this.beanFactory = beanFactory;
|
||||
|
@ -60,9 +62,7 @@ public class TypeExcludeFilter implements TypeFilter, BeanFactoryAware {
|
|||
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
|
||||
throws IOException {
|
||||
if (this.beanFactory instanceof ListableBeanFactory && getClass() == TypeExcludeFilter.class) {
|
||||
Collection<TypeExcludeFilter> delegates = ((ListableBeanFactory) this.beanFactory)
|
||||
.getBeansOfType(TypeExcludeFilter.class).values();
|
||||
for (TypeExcludeFilter delegate : delegates) {
|
||||
for (TypeExcludeFilter delegate : getDelegates()) {
|
||||
if (delegate.match(metadataReader, metadataReaderFactory)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -71,6 +71,15 @@ public class TypeExcludeFilter implements TypeFilter, BeanFactoryAware {
|
|||
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
|
||||
public boolean equals(Object obj) {
|
||||
throw new IllegalStateException("TypeExcludeFilter " + getClass() + " has not implemented equals");
|
||||
|
|
Loading…
Reference in New Issue