Last active
August 26, 2018 17:16
-
-
Save Bellov/babea73ef122545742dd316b9c910e23 to your computer and use it in GitHub Desktop.
Spring Boot Annotations
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
@SpringBootApllication | |
we use this annotation to mark the main class | |
@EnableAutoConfiguration | |
as its name says, enables auto-configuration. it means that Spring Boot looks for auto-configuration beans | |
@ConditionalOnClass and @conditionalOnMissingClass | |
using these conditions spring will only use the marked auto-configuration bean if the class in the | |
annotations argument is present/absent | |
@ConditionalOnBean and @ConditionalOnMissingBean | |
use these annotations when we want to define conditions basen on the presence or absence of a specific beans | |
@ConditionalOnProperty | |
With this annotation, we can make conditions on the values of properties | |
@ConditionalOnResource | |
We can make Spring to use a definition only when a specific resource is present | |
@ConditionalOnWebApplication and @ConditionalOnNotWebApplication | |
With these annotations, we can create conditions basen on if the current application is or isn`t web app | |
@ConditionalExpression | |
We can use this annotations in more complex situations, spring will use the marked definition when the | |
Spel expressions in evaluated to true | |
@Conditional | |
For even more complex conditions we can create a class eveluating the custom condition | |
we tell spring to use this custom condition with @Conditional | |
@EnableAsync | |
With this annotation, we can enable asynchronous functionality in Spring. We must use it with @Configuration | |
@EnableScheduling | |
With this annotation, we can enable scheduling in the app. We also have to use it in conjunction with @Configuration | |
@Async | |
We can define methods we want to execute on a different thread, hence run them asynchronously. | |
@Scheduled | |
If we need a method to execute periodically, we can use this annotation | |
@Transactional | |
When we want to configure the transactional behavior of a method. | |
@Param | |
We can pass named parameters to our queries using @Param | |
@Id | |
Marks a field in a model class as the primary key. | |
@Transient | |
We can use this annotaion to mark a field in a model class as transient. Hence the data store engine | |
wont read or write this field`s value | |
@CreatedBy | |
@LastModifiedBy | |
@CreatedDate | |
@LastModifiedDate | |
Whit these annotations, we can audit our model classes.Spring automatically populates the annotated fields with the | |
principal who created the object. | |
@Query | |
We can provide a JPQL implementation for a repository method. | |
@Repository | |
DAO or Repository classes usually represent the database access layer in the app. | |
@Service | |
The business logic of an app usually resides within te service layer | |
@Controller | |
Is class level annotation which tells the Spring what this class serves as a controller | |
@Configuration | |
Configuration classes can contain bean definition methods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment