Skip to content

Commit b904d52

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

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
@@ -896,16 +896,20 @@ public String getInitMethodName() {
896896
}
897897

898898
/**
899-
* Specify whether or not the configured init method is the default.
900-
* <p>The default value is {@code false}.
899+
* Specify whether or not the configured initializer method is the default.
900+
* <p>The default value is {@code true} for a locally specified init method
901+
* but switched to {@code false} for a shared setting in a defaults section
902+
* (e.g. {@code bean init-method} versus {@code beans default-init-method}
903+
* level in XML) which might not apply to all contained bean definitions.
901904
* @see #setInitMethodName
905+
* @see #applyDefaults
902906
*/
903907
public void setEnforceInitMethod(boolean enforceInitMethod) {
904908
this.enforceInitMethod = enforceInitMethod;
905909
}
906910

907911
/**
908-
* Indicate whether the configured init method is the default.
912+
* Indicate whether the configured initializer method is the default.
909913
* @see #getInitMethodName()
910914
*/
911915
public boolean isEnforceInitMethod() {
@@ -930,16 +934,20 @@ public String getDestroyMethodName() {
930934

931935
/**
932936
* Specify whether or not the configured destroy method is the default.
933-
* <p>The default value is {@code false}.
937+
* <p>The default value is {@code true} for a locally specified destroy method
938+
* but switched to {@code false} for a shared setting in a defaults section
939+
* (e.g. {@code bean destroy-method} versus {@code beans default-destroy-method}
940+
* level in XML) which might not apply to all contained bean definitions.
934941
* @see #setDestroyMethodName
942+
* @see #applyDefaults
935943
*/
936944
public void setEnforceDestroyMethod(boolean enforceDestroyMethod) {
937945
this.enforceDestroyMethod = enforceDestroyMethod;
938946
}
939947

940948
/**
941949
* Indicate whether the configured destroy method is the default.
942-
* @see #getDestroyMethodName
950+
* @see #getDestroyMethodName()
943951
*/
944952
public boolean isEnforceDestroyMethod() {
945953
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.
@@ -25,6 +25,7 @@
2525
* @author Mark Fisher
2626
* @author Juergen Hoeller
2727
* @since 2.5
28+
* @see AbstractBeanDefinition#applyDefaults
2829
*/
2930
public class BeanDefinitionDefaults {
3031

@@ -45,6 +46,7 @@ public class BeanDefinitionDefaults {
4546
* Set whether beans should be lazily initialized by default.
4647
* <p>If {@code false}, the bean will get instantiated on startup by bean
4748
* factories that perform eager initialization of singletons.
49+
* @see AbstractBeanDefinition#setLazyInit
4850
*/
4951
public void setLazyInit(boolean lazyInit) {
5052
this.lazyInit = lazyInit;
@@ -66,6 +68,7 @@ public boolean isLazyInit() {
6668
* (however, there may still be explicit annotation-driven autowiring).
6769
* @param autowireMode the autowire mode to set.
6870
* Must be one of the constants defined in {@link AbstractBeanDefinition}.
71+
* @see AbstractBeanDefinition#setAutowireMode
6972
*/
7073
public void setAutowireMode(int autowireMode) {
7174
this.autowireMode = autowireMode;
@@ -82,6 +85,7 @@ public int getAutowireMode() {
8285
* Set the dependency check code.
8386
* @param dependencyCheck the code to set.
8487
* Must be one of the constants defined in {@link AbstractBeanDefinition}.
88+
* @see AbstractBeanDefinition#setDependencyCheck
8589
*/
8690
public void setDependencyCheck(int dependencyCheck) {
8791
this.dependencyCheck = dependencyCheck;
@@ -96,6 +100,10 @@ public int getDependencyCheck() {
96100

97101
/**
98102
* Set the name of the default initializer method.
103+
* <p>Note that this method is not enforced on all affected bean definitions
104+
* but rather taken as an optional callback, to be invoked if actually present.
105+
* @see AbstractBeanDefinition#setInitMethodName
106+
* @see AbstractBeanDefinition#setEnforceInitMethod
99107
*/
100108
public void setInitMethodName(@Nullable String initMethodName) {
101109
this.initMethodName = (StringUtils.hasText(initMethodName) ? initMethodName : null);
@@ -111,6 +119,10 @@ public String getInitMethodName() {
111119

112120
/**
113121
* Set the name of the default destroy method.
122+
* <p>Note that this method is not enforced on all affected bean definitions
123+
* but rather taken as an optional callback, to be invoked if actually present.
124+
* @see AbstractBeanDefinition#setDestroyMethodName
125+
* @see AbstractBeanDefinition#setEnforceDestroyMethod
114126
*/
115127
public void setDestroyMethodName(@Nullable String destroyMethodName) {
116128
this.destroyMethodName = (StringUtils.hasText(destroyMethodName) ? destroyMethodName : null);

0 commit comments

Comments
 (0)