Avoid unnecessary trace logging in ProxyFactoryBean
Closes gh-24669
This commit is contained in:
		
							parent
							
								
									1c6dda3ca4
								
							
						
					
					
						commit
						fdc60311ed
					
				|  | @ -21,9 +21,7 @@ import java.io.ObjectInputStream; | ||||||
| import java.io.Serializable; | import java.io.Serializable; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.Arrays; | import java.util.Arrays; | ||||||
| import java.util.HashMap; |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; |  | ||||||
| 
 | 
 | ||||||
| import org.aopalliance.aop.Advice; | import org.aopalliance.aop.Advice; | ||||||
| import org.aopalliance.intercept.Interceptor; | import org.aopalliance.intercept.Interceptor; | ||||||
|  | @ -342,11 +340,8 @@ public class ProxyFactoryBean extends ProxyCreatorSupport | ||||||
| 		// an independent instance of the configuration. | 		// an independent instance of the configuration. | ||||||
| 		// In this case, no proxy will have an instance of this object's configuration, | 		// In this case, no proxy will have an instance of this object's configuration, | ||||||
| 		// but will have an independent copy. | 		// but will have an independent copy. | ||||||
| 		if (logger.isTraceEnabled()) { |  | ||||||
| 			logger.trace("Creating copy of prototype ProxyFactoryBean config: " + this); |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		ProxyCreatorSupport copy = new ProxyCreatorSupport(getAopProxyFactory()); | 		ProxyCreatorSupport copy = new ProxyCreatorSupport(getAopProxyFactory()); | ||||||
|  | 
 | ||||||
| 		// The copy needs a fresh advisor chain, and a fresh TargetSource. | 		// The copy needs a fresh advisor chain, and a fresh TargetSource. | ||||||
| 		TargetSource targetSource = freshTargetSource(); | 		TargetSource targetSource = freshTargetSource(); | ||||||
| 		copy.copyConfigurationFrom(this, targetSource, freshAdvisorChain()); | 		copy.copyConfigurationFrom(this, targetSource, freshAdvisorChain()); | ||||||
|  | @ -359,9 +354,6 @@ public class ProxyFactoryBean extends ProxyCreatorSupport | ||||||
| 		} | 		} | ||||||
| 		copy.setFrozen(this.freezeProxy); | 		copy.setFrozen(this.freezeProxy); | ||||||
| 
 | 
 | ||||||
| 		if (logger.isTraceEnabled()) { |  | ||||||
| 			logger.trace("Using ProxyCreatorSupport copy: " + copy); |  | ||||||
| 		} |  | ||||||
| 		return getProxy(copy.createAopProxy()); | 		return getProxy(copy.createAopProxy()); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -447,16 +439,12 @@ public class ProxyFactoryBean extends ProxyCreatorSupport | ||||||
| 
 | 
 | ||||||
| 			// Materialize interceptor chain from bean names. | 			// Materialize interceptor chain from bean names. | ||||||
| 			for (String name : this.interceptorNames) { | 			for (String name : this.interceptorNames) { | ||||||
| 				if (logger.isTraceEnabled()) { |  | ||||||
| 					logger.trace("Configuring advisor or advice '" + name + "'"); |  | ||||||
| 				} |  | ||||||
| 
 |  | ||||||
| 				if (name.endsWith(GLOBAL_SUFFIX)) { | 				if (name.endsWith(GLOBAL_SUFFIX)) { | ||||||
| 					if (!(this.beanFactory instanceof ListableBeanFactory)) { | 					if (!(this.beanFactory instanceof ListableBeanFactory)) { | ||||||
| 						throw new AopConfigException( | 						throw new AopConfigException( | ||||||
| 								"Can only use global advisors or interceptors with a ListableBeanFactory"); | 								"Can only use global advisors or interceptors with a ListableBeanFactory"); | ||||||
| 					} | 					} | ||||||
| 					addGlobalAdvisor((ListableBeanFactory) this.beanFactory, | 					addGlobalAdvisors((ListableBeanFactory) this.beanFactory, | ||||||
| 							name.substring(0, name.length() - GLOBAL_SUFFIX.length())); | 							name.substring(0, name.length() - GLOBAL_SUFFIX.length())); | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
|  | @ -473,7 +461,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport | ||||||
| 						// Avoid unnecessary creation of prototype bean just for advisor chain initialization. | 						// Avoid unnecessary creation of prototype bean just for advisor chain initialization. | ||||||
| 						advice = new PrototypePlaceholderAdvisor(name); | 						advice = new PrototypePlaceholderAdvisor(name); | ||||||
| 					} | 					} | ||||||
| 					addAdvisorOnChainCreation(advice, name); | 					addAdvisorOnChainCreation(advice); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | @ -496,11 +484,10 @@ public class ProxyFactoryBean extends ProxyCreatorSupport | ||||||
| 				if (logger.isDebugEnabled()) { | 				if (logger.isDebugEnabled()) { | ||||||
| 					logger.debug("Refreshing bean named '" + pa.getBeanName() + "'"); | 					logger.debug("Refreshing bean named '" + pa.getBeanName() + "'"); | ||||||
| 				} | 				} | ||||||
| 				// Replace the placeholder with a fresh prototype instance resulting | 				// Replace the placeholder with a fresh prototype instance resulting from a getBean lookup | ||||||
| 				// from a getBean() lookup |  | ||||||
| 				if (this.beanFactory == null) { | 				if (this.beanFactory == null) { | ||||||
| 					throw new IllegalStateException("No BeanFactory available anymore (probably due to serialization) " + | 					throw new IllegalStateException("No BeanFactory available anymore (probably due to " + | ||||||
| 							"- cannot resolve prototype advisor '" + pa.getBeanName() + "'"); | 							"serialization) - cannot resolve prototype advisor '" + pa.getBeanName() + "'"); | ||||||
| 				} | 				} | ||||||
| 				Object bean = this.beanFactory.getBean(pa.getBeanName()); | 				Object bean = this.beanFactory.getBean(pa.getBeanName()); | ||||||
| 				Advisor refreshedAdvisor = namedBeanToAdvisor(bean); | 				Advisor refreshedAdvisor = namedBeanToAdvisor(bean); | ||||||
|  | @ -517,28 +504,26 @@ public class ProxyFactoryBean extends ProxyCreatorSupport | ||||||
| 	/** | 	/** | ||||||
| 	 * Add all global interceptors and pointcuts. | 	 * Add all global interceptors and pointcuts. | ||||||
| 	 */ | 	 */ | ||||||
| 	private void addGlobalAdvisor(ListableBeanFactory beanFactory, String prefix) { | 	private void addGlobalAdvisors(ListableBeanFactory beanFactory, String prefix) { | ||||||
| 		String[] globalAdvisorNames = | 		String[] globalAdvisorNames = | ||||||
| 				BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, Advisor.class); | 				BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, Advisor.class); | ||||||
| 		String[] globalInterceptorNames = | 		String[] globalInterceptorNames = | ||||||
| 				BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, Interceptor.class); | 				BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, Interceptor.class); | ||||||
|  | 		if (globalAdvisorNames.length > 0 || globalInterceptorNames.length > 0) { | ||||||
| 			List<Object> beans = new ArrayList<>(globalAdvisorNames.length + globalInterceptorNames.length); | 			List<Object> beans = new ArrayList<>(globalAdvisorNames.length + globalInterceptorNames.length); | ||||||
| 		Map<Object, String> names = new HashMap<>(beans.size()); |  | ||||||
| 			for (String name : globalAdvisorNames) { | 			for (String name : globalAdvisorNames) { | ||||||
| 			Object bean = beanFactory.getBean(name); | 				if (name.startsWith(prefix)) { | ||||||
| 			beans.add(bean); | 					beans.add(beanFactory.getBean(name)); | ||||||
| 			names.put(bean, name); | 				} | ||||||
| 			} | 			} | ||||||
| 			for (String name : globalInterceptorNames) { | 			for (String name : globalInterceptorNames) { | ||||||
| 			Object bean = beanFactory.getBean(name); | 				if (name.startsWith(prefix)) { | ||||||
| 			beans.add(bean); | 					beans.add(beanFactory.getBean(name)); | ||||||
| 			names.put(bean, name); | 				} | ||||||
| 			} | 			} | ||||||
| 			AnnotationAwareOrderComparator.sort(beans); | 			AnnotationAwareOrderComparator.sort(beans); | ||||||
| 			for (Object bean : beans) { | 			for (Object bean : beans) { | ||||||
| 			String name = names.get(bean); | 				addAdvisorOnChainCreation(bean); | ||||||
| 			if (name.startsWith(prefix)) { |  | ||||||
| 				addAdvisorOnChainCreation(bean, name); |  | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | @ -549,17 +534,11 @@ public class ProxyFactoryBean extends ProxyCreatorSupport | ||||||
| 	 * Because of these three possibilities, we can't type the signature | 	 * Because of these three possibilities, we can't type the signature | ||||||
| 	 * more strongly. | 	 * more strongly. | ||||||
| 	 * @param next advice, advisor or target object | 	 * @param next advice, advisor or target object | ||||||
| 	 * @param name bean name from which we obtained this object in our owning |  | ||||||
| 	 * bean factory |  | ||||||
| 	 */ | 	 */ | ||||||
| 	private void addAdvisorOnChainCreation(Object next, String name) { | 	private void addAdvisorOnChainCreation(Object next) { | ||||||
| 		// We need to convert to an Advisor if necessary so that our source reference | 		// We need to convert to an Advisor if necessary so that our source reference | ||||||
| 		// matches what we find from superclass interceptors. | 		// matches what we find from superclass interceptors. | ||||||
| 		Advisor advisor = namedBeanToAdvisor(next); | 		addAdvisor(namedBeanToAdvisor(next)); | ||||||
| 		if (logger.isTraceEnabled()) { |  | ||||||
| 			logger.trace("Adding advisor with name '" + name + "'"); |  | ||||||
| 		} |  | ||||||
| 		addAdvisor(advisor); |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/** | 	/** | ||||||
|  | @ -570,9 +549,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport | ||||||
| 	 */ | 	 */ | ||||||
| 	private TargetSource freshTargetSource() { | 	private TargetSource freshTargetSource() { | ||||||
| 		if (this.targetName == null) { | 		if (this.targetName == null) { | ||||||
| 			if (logger.isTraceEnabled()) { | 			// Not refreshing target: bean name not specified in 'interceptorNames' | ||||||
| 				logger.trace("Not refreshing target: Bean name not specified in 'interceptorNames'."); |  | ||||||
| 			} |  | ||||||
| 			return this.targetSource; | 			return this.targetSource; | ||||||
| 		} | 		} | ||||||
| 		else { | 		else { | ||||||
|  | @ -612,7 +589,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport | ||||||
| 	protected void adviceChanged() { | 	protected void adviceChanged() { | ||||||
| 		super.adviceChanged(); | 		super.adviceChanged(); | ||||||
| 		if (this.singleton) { | 		if (this.singleton) { | ||||||
| 			logger.debug("Advice has changed; recaching singleton instance"); | 			logger.debug("Advice has changed; re-caching singleton instance"); | ||||||
| 			synchronized (this) { | 			synchronized (this) { | ||||||
| 				this.singletonInstance = null; | 				this.singletonInstance = null; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue