Skip to content

Commit 94d459e

Browse files
committed
Clarify enforceInitMethod/enforceDestroyMethod default values
Closes gh-25402 (cherry picked from commit 5846d9c)
1 parent b5887bf commit 94d459e

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -809,16 +809,20 @@ public String getInitMethodName() {
809809
}
810810

811811
/**
812-
* Specify whether or not the configured init method is the default.
813-
* <p>The default value is {@code false}.
812+
* Specify whether or not the configured initializer method is the default.
813+
* <p>The default value is {@code true} for a locally specified init method
814+
* but switched to {@code false} for a shared setting in a defaults section
815+
* (e.g. {@code bean init-method} versus {@code beans default-init-method}
816+
* level in XML) which might not apply to all contained bean definitions.
814817
* @see #setInitMethodName
818+
* @see #applyDefaults
815819
*/
816820
public void setEnforceInitMethod(boolean enforceInitMethod) {
817821
this.enforceInitMethod = enforceInitMethod;
818822
}
819823

820824
/**
821-
* Indicate whether the configured init method is the default.
825+
* Indicate whether the configured initializer method is the default.
822826
* @see #getInitMethodName()
823827
*/
824828
public boolean isEnforceInitMethod() {
@@ -842,16 +846,20 @@ public String getDestroyMethodName() {
842846

843847
/**
844848
* Specify whether or not the configured destroy method is the default.
845-
* <p>The default value is {@code false}.
849+
* <p>The default value is {@code true} for a locally specified destroy method
850+
* but switched to {@code false} for a shared setting in a defaults section
851+
* (e.g. {@code bean destroy-method} versus {@code beans default-destroy-method}
852+
* level in XML) which might not apply to all contained bean definitions.
846853
* @see #setDestroyMethodName
854+
* @see #applyDefaults
847855
*/
848856
public void setEnforceDestroyMethod(boolean enforceDestroyMethod) {
849857
this.enforceDestroyMethod = enforceDestroyMethod;
850858
}
851859

852860
/**
853861
* Indicate whether the configured destroy method is the default.
854-
* @see #getDestroyMethodName
862+
* @see #getDestroyMethodName()
855863
*/
856864
public boolean isEnforceDestroyMethod() {
857865
return this.enforceDestroyMethod;

spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
* @author Mark Fisher
2525
* @author Juergen Hoeller
2626
* @since 2.5
27+
* @see AbstractBeanDefinition#applyDefaults
2728
*/
2829
public class BeanDefinitionDefaults {
2930

@@ -42,6 +43,7 @@ public class BeanDefinitionDefaults {
4243
* Set whether beans should be lazily initialized by default.
4344
* <p>If {@code false}, the bean will get instantiated on startup by bean
4445
* factories that perform eager initialization of singletons.
46+
* @see AbstractBeanDefinition#setLazyInit
4547
*/
4648
public void setLazyInit(boolean lazyInit) {
4749
this.lazyInit = lazyInit;
@@ -63,6 +65,7 @@ public boolean isLazyInit() {
6365
* (however, there may still be explicit annotation-driven autowiring).
6466
* @param autowireMode the autowire mode to set.
6567
* Must be one of the constants defined in {@link AbstractBeanDefinition}.
68+
* @see AbstractBeanDefinition#setAutowireMode
6669
*/
6770
public void setAutowireMode(int autowireMode) {
6871
this.autowireMode = autowireMode;
@@ -79,6 +82,7 @@ public int getAutowireMode() {
7982
* Set the dependency check code.
8083
* @param dependencyCheck the code to set.
8184
* Must be one of the constants defined in {@link AbstractBeanDefinition}.
85+
* @see AbstractBeanDefinition#setDependencyCheck
8286
*/
8387
public void setDependencyCheck(int dependencyCheck) {
8488
this.dependencyCheck = dependencyCheck;
@@ -93,6 +97,10 @@ public int getDependencyCheck() {
9397

9498
/**
9599
* Set the name of the default initializer method.
100+
* <p>Note that this method is not enforced on all affected bean definitions
101+
* but rather taken as an optional callback, to be invoked if actually present.
102+
* @see AbstractBeanDefinition#setInitMethodName
103+
* @see AbstractBeanDefinition#setEnforceInitMethod
96104
*/
97105
public void setInitMethodName(String initMethodName) {
98106
this.initMethodName = (StringUtils.hasText(initMethodName) ? initMethodName : null);
@@ -107,6 +115,10 @@ public String getInitMethodName() {
107115

108116
/**
109117
* Set the name of the default destroy method.
118+
* <p>Note that this method is not enforced on all affected bean definitions
119+
* but rather taken as an optional callback, to be invoked if actually present.
120+
* @see AbstractBeanDefinition#setDestroyMethodName
121+
* @see AbstractBeanDefinition#setEnforceDestroyMethod
110122
*/
111123
public void setDestroyMethodName(String destroyMethodName) {
112124
this.destroyMethodName = (StringUtils.hasText(destroyMethodName) ? destroyMethodName : null);

0 commit comments

Comments
 (0)