Skip to content

Commit 73da153

Browse files
committed
DisposableBean javadoc refers to singletons as well as scoped beans
Issue: SPR-17131 (cherry picked from commit f155d21)
1 parent 75b323e commit 73da153

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/DisposableBean.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -17,27 +17,29 @@
1717
package org.springframework.beans.factory;
1818

1919
/**
20-
* Interface to be implemented by beans that want to release resources
21-
* on destruction. A BeanFactory is supposed to invoke the destroy
22-
* method if it disposes a cached singleton. An application context
23-
* is supposed to dispose all of its singletons on close.
20+
* Interface to be implemented by beans that want to release resources on destruction.
21+
* A {@link BeanFactory} will invoke the destroy method on individual destruction of a
22+
* scoped bean. An {@link org.springframework.context.ApplicationContext} is supposed
23+
* to dispose all of its singletons on shutdown, driven by the application lifecycle.
2424
*
25-
* <p>An alternative to implementing DisposableBean is specifying a custom
26-
* destroy-method, for example in an XML bean definition.
27-
* For a list of all bean lifecycle methods, see the BeanFactory javadocs.
25+
* <p>A Spring-managed bean may also implement Java's {@link AutoCloseable} interface
26+
* for the same purpose. An alternative to implementing an interface is specifying a
27+
* custom destroy method, for example in an XML bean definition. For a list of all
28+
* bean lifecycle methods, see the {@link BeanFactory BeanFactory javadocs}.
2829
*
2930
* @author Juergen Hoeller
3031
* @since 12.08.2003
31-
* @see org.springframework.beans.factory.support.RootBeanDefinition#getDestroyMethodName
32-
* @see org.springframework.context.ConfigurableApplicationContext#close
32+
* @see InitializingBean
33+
* @see org.springframework.beans.factory.support.RootBeanDefinition#getDestroyMethodName()
34+
* @see org.springframework.beans.factory.config.ConfigurableBeanFactory#destroySingletons()
35+
* @see org.springframework.context.ConfigurableApplicationContext#close()
3336
*/
3437
public interface DisposableBean {
3538

3639
/**
37-
* Invoked by a BeanFactory on destruction of a singleton.
38-
* @throws Exception in case of shutdown errors.
39-
* Exceptions will get logged but not rethrown to allow
40-
* other beans to release their resources too.
40+
* Invoked by the containing {@code BeanFactory} on destruction of a bean.
41+
* @throws Exception in case of shutdown errors. Exceptions will get logged
42+
* but not rethrown to allow other beans to release their resources as well.
4143
*/
4244
void destroy() throws Exception;
4345

spring-beans/src/main/java/org/springframework/beans/factory/InitializingBean.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -17,31 +17,29 @@
1717
package org.springframework.beans.factory;
1818

1919
/**
20-
* Interface to be implemented by beans that need to react once all their
21-
* properties have been set by a BeanFactory: for example, to perform custom
22-
* initialization, or merely to check that all mandatory properties have been set.
20+
* Interface to be implemented by beans that need to react once all their properties
21+
* have been set by a {@link BeanFactory}: e.g. to perform custom initialization,
22+
* or merely to check that all mandatory properties have been set.
2323
*
24-
* <p>An alternative to implementing InitializingBean is specifying a custom
25-
* init-method, for example in an XML bean definition.
26-
* For a list of all bean lifecycle methods, see the BeanFactory javadocs.
24+
* <p>An alternative to implementing {@code InitializingBean} is specifying a custom
25+
* init method, for example in an XML bean definition. For a list of all bean
26+
* lifecycle methods, see the {@link BeanFactory BeanFactory javadocs}.
2727
*
2828
* @author Rod Johnson
29-
* @see BeanNameAware
30-
* @see BeanFactoryAware
31-
* @see BeanFactory
32-
* @see org.springframework.beans.factory.support.RootBeanDefinition#getInitMethodName
33-
* @see org.springframework.context.ApplicationContextAware
29+
* @author Juergen Hoeller
30+
* @see DisposableBean
31+
* @see org.springframework.beans.factory.config.BeanDefinition#getPropertyValues()
32+
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getInitMethodName()
3433
*/
3534
public interface InitializingBean {
3635

3736
/**
38-
* Invoked by a BeanFactory after it has set all bean properties supplied
39-
* (and satisfied BeanFactoryAware and ApplicationContextAware).
40-
* <p>This method allows the bean instance to perform initialization only
41-
* possible when all bean properties have been set and to throw an
42-
* exception in the event of misconfiguration.
43-
* @throws Exception in the event of misconfiguration (such
44-
* as failure to set an essential property) or if initialization fails.
37+
* Invoked by the containing {@code BeanFactory} after it has set all bean properties
38+
* and satisfied {@link BeanFactoryAware}, {@code ApplicationContextAware} etc.
39+
* <p>This method allows the bean instance to perform validation of its overall
40+
* configuration and final initialization when all bean properties have been set.
41+
* @throws Exception in the event of misconfiguration (such as failure to set an
42+
* essential property) or if initialization fails for any other reason
4543
*/
4644
void afterPropertiesSet() throws Exception;
4745

spring-beans/src/main/java/org/springframework/beans/factory/config/DestructionAwareBeanPostProcessor.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -30,16 +30,16 @@
3030
public interface DestructionAwareBeanPostProcessor extends BeanPostProcessor {
3131

3232
/**
33-
* Apply this BeanPostProcessor to the given bean instance before
34-
* its destruction. Can invoke custom destruction callbacks.
35-
* <p>Like DisposableBean's {@code destroy} and a custom destroy method,
36-
* this callback just applies to singleton beans in the factory (including
37-
* inner beans).
33+
* Apply this BeanPostProcessor to the given bean instance before its
34+
* destruction, e.g. invoking custom destruction callbacks.
35+
* <p>Like DisposableBean's {@code destroy} and a custom destroy method, this
36+
* callback will only apply to beans which the container fully manages the
37+
* lifecycle for. This is usually the case for singletons and scoped beans.
3838
* @param bean the bean instance to be destroyed
3939
* @param beanName the name of the bean
4040
* @throws org.springframework.beans.BeansException in case of errors
41-
* @see org.springframework.beans.factory.DisposableBean
42-
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#setDestroyMethodName
41+
* @see org.springframework.beans.factory.DisposableBean#destroy()
42+
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#setDestroyMethodName(String)
4343
*/
4444
void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException;
4545

0 commit comments

Comments
 (0)