Spring#
TODO#
Bean lifecycle#
Use annotations
@PostConstruct,@PreDestroy,@BeanImplement
InitializingBeanDisposableBean
@Bean vs @Component#
The @Bean and @Component annotation’s can be used to create beans that can be injected into each other.
The
@Beanannotation is a method-level annotation, whereas@Componentis a class-level annotation.The
@Componentannotation doesn’t need to be used with the@Configurationannotation, whereas the@Beangeneric annotation has to be used within a class annotated with @Configuration.If you want to create a single bean for a class from an external library, you cannot just add the
@Componentannotation because you cannot edit the class. However, you can declare a method annotated with @Bean and return an object of this class from this method.There are several specializations of the
@Componentannotation, whereas@Beandoesn’t have any specialized stereotype annotations.
Spring developers typically prefer Spring @Component annotation whenever possible. The @Bean annotation is mainly used for producing beans of unmodifiable classes or creating configs.
Specializations of components in Spring#
As mentioned above, there are several specializations of components depending on their role in Spring applications:
@Componentindicates a generic Spring component.@Serviceindicates a business logic component but doesn’t provide any additional functions.@Controller/@RestControllerindicates a component that can work in REST web services.@Repositoryindicates a component that interacts with an external data storage (e.g., a database).
Transaction propagations#
Type |
|---|
|
|
|
|
|
|
|
Solution Architecture Document#
Draft#
Common annotations
Annotation |
Description |
|---|---|
|
Enable auto-configuration of Spring Application Context, attempts to guess and configure the beans that you are likely to need based on the classpath and the beans you’ve already set up. |
|
Composition annotation of |
|
Indicates that class declares one or more |
|
|
|
|
|
|
|
Design Patterns Used in Spring Framework#
Factory
Inversion of Control
Proxy
Spring Cloud#
Distributed/versioned configuration
Service registration and discovery
Routing
Service-to-service calls
Load balancing
Circuit Breakers
Global locks
Leadership election and cluster state
Distributed messaging