-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BLZT-105] - PreDestroy.md was added, minor fixes
- Loading branch information
zburole
committed
Dec 1, 2023
1 parent
d9f9eba
commit 2ed2697
Showing
4 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# PreDestroy | ||
|
||
## Introduction | ||
|
||
The `@PreDestroy` annotation is used to signal that the annotated method | ||
should be executed before the container removes the instance of the class | ||
in which the method is declared. This is typically used for cleanup operations | ||
or releasing resources held by the instance. | ||
|
||
The annotated method must have no parameters, must be non-static and return void. | ||
It is invoked before the bean is destroyed, allowing the bean to perform necessary cleanup tasks. | ||
If multiple methods are annotated with {@code @PreDestroy} within a single | ||
class, the order of execution is not guaranteed. | ||
|
||
## Usage | ||
|
||
```java | ||
@Component | ||
public class CustomerRepository { | ||
|
||
private DbConnection dbConnection; | ||
@PreDestroy | ||
public void close() { | ||
dbConnection.close(); | ||
} | ||
} | ||
``` | ||
The `@PreDestroy` annotated method will be automatically invoked on context closing. | ||
|
||
## Important Points | ||
|
||
- The method annotated with `@PreDestroy` must not have any parameters. | ||
- This annotation is generally used in conjunction with the `@Component` stereotype annotations (e.g., `@Service`, `@Repository`, `@Controller`) or in configuration classes. | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters