Skip to content

Commit fdc6031

Browse files
committed
Avoid unnecessary trace logging in ProxyFactoryBean
Closes gh-24669
1 parent 1c6dda3 commit fdc6031

File tree

1 file changed

+26
-49
lines changed

1 file changed

+26
-49
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
import java.io.Serializable;
2222
import java.util.ArrayList;
2323
import java.util.Arrays;
24-
import java.util.HashMap;
2524
import java.util.List;
26-
import java.util.Map;
2725

2826
import org.aopalliance.aop.Advice;
2927
import org.aopalliance.intercept.Interceptor;
@@ -342,11 +340,8 @@ private synchronized Object newPrototypeInstance() {
342340
// an independent instance of the configuration.
343341
// In this case, no proxy will have an instance of this object's configuration,
344342
// but will have an independent copy.
345-
if (logger.isTraceEnabled()) {
346-
logger.trace("Creating copy of prototype ProxyFactoryBean config: " + this);
347-
}
348-
349343
ProxyCreatorSupport copy = new ProxyCreatorSupport(getAopProxyFactory());
344+
350345
// The copy needs a fresh advisor chain, and a fresh TargetSource.
351346
TargetSource targetSource = freshTargetSource();
352347
copy.copyConfigurationFrom(this, targetSource, freshAdvisorChain());
@@ -359,9 +354,6 @@ private synchronized Object newPrototypeInstance() {
359354
}
360355
copy.setFrozen(this.freezeProxy);
361356

362-
if (logger.isTraceEnabled()) {
363-
logger.trace("Using ProxyCreatorSupport copy: " + copy);
364-
}
365357
return getProxy(copy.createAopProxy());
366358
}
367359

@@ -447,16 +439,12 @@ private synchronized void initializeAdvisorChain() throws AopConfigException, Be
447439

448440
// Materialize interceptor chain from bean names.
449441
for (String name : this.interceptorNames) {
450-
if (logger.isTraceEnabled()) {
451-
logger.trace("Configuring advisor or advice '" + name + "'");
452-
}
453-
454442
if (name.endsWith(GLOBAL_SUFFIX)) {
455443
if (!(this.beanFactory instanceof ListableBeanFactory)) {
456444
throw new AopConfigException(
457445
"Can only use global advisors or interceptors with a ListableBeanFactory");
458446
}
459-
addGlobalAdvisor((ListableBeanFactory) this.beanFactory,
447+
addGlobalAdvisors((ListableBeanFactory) this.beanFactory,
460448
name.substring(0, name.length() - GLOBAL_SUFFIX.length()));
461449
}
462450

@@ -473,7 +461,7 @@ private synchronized void initializeAdvisorChain() throws AopConfigException, Be
473461
// Avoid unnecessary creation of prototype bean just for advisor chain initialization.
474462
advice = new PrototypePlaceholderAdvisor(name);
475463
}
476-
addAdvisorOnChainCreation(advice, name);
464+
addAdvisorOnChainCreation(advice);
477465
}
478466
}
479467
}
@@ -496,11 +484,10 @@ private List<Advisor> freshAdvisorChain() {
496484
if (logger.isDebugEnabled()) {
497485
logger.debug("Refreshing bean named '" + pa.getBeanName() + "'");
498486
}
499-
// Replace the placeholder with a fresh prototype instance resulting
500-
// from a getBean() lookup
487+
// Replace the placeholder with a fresh prototype instance resulting from a getBean lookup
501488
if (this.beanFactory == null) {
502-
throw new IllegalStateException("No BeanFactory available anymore (probably due to serialization) " +
503-
"- cannot resolve prototype advisor '" + pa.getBeanName() + "'");
489+
throw new IllegalStateException("No BeanFactory available anymore (probably due to " +
490+
"serialization) - cannot resolve prototype advisor '" + pa.getBeanName() + "'");
504491
}
505492
Object bean = this.beanFactory.getBean(pa.getBeanName());
506493
Advisor refreshedAdvisor = namedBeanToAdvisor(bean);
@@ -517,28 +504,26 @@ private List<Advisor> freshAdvisorChain() {
517504
/**
518505
* Add all global interceptors and pointcuts.
519506
*/
520-
private void addGlobalAdvisor(ListableBeanFactory beanFactory, String prefix) {
507+
private void addGlobalAdvisors(ListableBeanFactory beanFactory, String prefix) {
521508
String[] globalAdvisorNames =
522509
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, Advisor.class);
523510
String[] globalInterceptorNames =
524511
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, Interceptor.class);
525-
List<Object> beans = new ArrayList<>(globalAdvisorNames.length + globalInterceptorNames.length);
526-
Map<Object, String> names = new HashMap<>(beans.size());
527-
for (String name : globalAdvisorNames) {
528-
Object bean = beanFactory.getBean(name);
529-
beans.add(bean);
530-
names.put(bean, name);
531-
}
532-
for (String name : globalInterceptorNames) {
533-
Object bean = beanFactory.getBean(name);
534-
beans.add(bean);
535-
names.put(bean, name);
536-
}
537-
AnnotationAwareOrderComparator.sort(beans);
538-
for (Object bean : beans) {
539-
String name = names.get(bean);
540-
if (name.startsWith(prefix)) {
541-
addAdvisorOnChainCreation(bean, name);
512+
if (globalAdvisorNames.length > 0 || globalInterceptorNames.length > 0) {
513+
List<Object> beans = new ArrayList<>(globalAdvisorNames.length + globalInterceptorNames.length);
514+
for (String name : globalAdvisorNames) {
515+
if (name.startsWith(prefix)) {
516+
beans.add(beanFactory.getBean(name));
517+
}
518+
}
519+
for (String name : globalInterceptorNames) {
520+
if (name.startsWith(prefix)) {
521+
beans.add(beanFactory.getBean(name));
522+
}
523+
}
524+
AnnotationAwareOrderComparator.sort(beans);
525+
for (Object bean : beans) {
526+
addAdvisorOnChainCreation(bean);
542527
}
543528
}
544529
}
@@ -549,17 +534,11 @@ private void addGlobalAdvisor(ListableBeanFactory beanFactory, String prefix) {
549534
* Because of these three possibilities, we can't type the signature
550535
* more strongly.
551536
* @param next advice, advisor or target object
552-
* @param name bean name from which we obtained this object in our owning
553-
* bean factory
554537
*/
555-
private void addAdvisorOnChainCreation(Object next, String name) {
538+
private void addAdvisorOnChainCreation(Object next) {
556539
// We need to convert to an Advisor if necessary so that our source reference
557540
// matches what we find from superclass interceptors.
558-
Advisor advisor = namedBeanToAdvisor(next);
559-
if (logger.isTraceEnabled()) {
560-
logger.trace("Adding advisor with name '" + name + "'");
561-
}
562-
addAdvisor(advisor);
541+
addAdvisor(namedBeanToAdvisor(next));
563542
}
564543

565544
/**
@@ -570,9 +549,7 @@ private void addAdvisorOnChainCreation(Object next, String name) {
570549
*/
571550
private TargetSource freshTargetSource() {
572551
if (this.targetName == null) {
573-
if (logger.isTraceEnabled()) {
574-
logger.trace("Not refreshing target: Bean name not specified in 'interceptorNames'.");
575-
}
552+
// Not refreshing target: bean name not specified in 'interceptorNames'
576553
return this.targetSource;
577554
}
578555
else {
@@ -612,7 +589,7 @@ private Advisor namedBeanToAdvisor(Object next) {
612589
protected void adviceChanged() {
613590
super.adviceChanged();
614591
if (this.singleton) {
615-
logger.debug("Advice has changed; recaching singleton instance");
592+
logger.debug("Advice has changed; re-caching singleton instance");
616593
synchronized (this) {
617594
this.singletonInstance = null;
618595
}

0 commit comments

Comments
 (0)