Skip to content

Commit

Permalink
[BLZT-105] - PreDestroy.md was added, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zburole committed Dec 1, 2023
1 parent d9f9eba commit 2ed2697
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* 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 @PostConstruct} within a single
* If multiple methods are annotated with {@code @PreDestroy} within a single
* class, the order of execution is not guaranteed.</p>
*
* <p>Example of usage:</p>
Expand Down
5 changes: 3 additions & 2 deletions features/Core.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ It initializes the list with default post-processors such as the ScheduleBeanPos
- [@Configuration](https://yevgendemotestorganization.github.io/bring-core-javadoc/com/bobocode/bring/core/annotation/Configuration.html)
- [@Order](https://yevgendemotestorganization.github.io/bring-core-javadoc/com/bobocode/bring/core/annotation/Order.html)
- [@PostConstruct](core/PostConstruct.md)
- [@Primary](https://yevgendemotestorganization.github.io/bring-core-javadoc/com/bobocode/bring/core/annotation/Primary.html)
- [@Qualifier](https://yevgendemotestorganization.github.io/bring-core-javadoc/com/bobocode/bring/core/annotation/Qualifier.html)
- [@PreDestroy](core/PreDestroy.md)
- [@Primary](core/Primary.md)
- [@Qualifier](core/Qualifier.md)
- [@ScheduledTask](https://yevgendemotestorganization.github.io/bring-core-javadoc/com/bobocode/bring/core/annotation/ScheduledTask.html)
- [@Scope](https://yevgendemotestorganization.github.io/bring-core-javadoc/com/bobocode/bring/core/annotation/package-summary.html#:~:text=a%20scheduled%20task.-,Scope,-Annotation%20indicating%20the)
- [@Service](https://yevgendemotestorganization.github.io/bring-core-javadoc/com/bobocode/bring/core/annotation/Service.html)
Expand Down
37 changes: 37 additions & 0 deletions features/core/PreDestroy.md
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.




5 changes: 5 additions & 0 deletions features/core/Qualifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,10 @@ Next, initiate the application context and check what will be returned by playMu
The assertion indicates that the ambiguity has been resolved for both parameters using the @Qualifier
annotation during the autowiring process.
## Important Points
Bring supports several options for disambiguating the search for dependencies for injection.
If it is necessary to inject a dependency and there are several suitable beans of the same type,
then Bring initially tries to disambiguate with the help of `@Primary`, then with the help of `@Qualifier`
and ultimately by matching the bean names and field/parameter names

0 comments on commit 2ed2697

Please sign in to comment.