All Projects → gindex → spring-boot-annotation-list

gindex / spring-boot-annotation-list

Licence: CC0-1.0 License
Curated list of frequently used annotations in Spring Boot applications

Projects that are alternatives of or similar to spring-boot-annotation-list

Knowledge Graph Wander
A collection of papers, codes, projects, tutorials ... for Knowledge Graph and other NLP methods
Stars: ✭ 26 (-38.1%)
Mutual labels:  curated-list
online-shopping
This is an online shopping project using Spring Boot,Spring web-flow, Spring Rest Services and Hibernate. In this project we also used Spring Security with java and annotation configuration
Stars: ✭ 34 (-19.05%)
Mutual labels:  springframework
opa-java-spring-client
Simple Spring client for working with the Open Policy Agent
Stars: ✭ 19 (-54.76%)
Mutual labels:  springframework
Spring
Personal notes of preparation to Spring 5 Professional Certification
Stars: ✭ 35 (-16.67%)
Mutual labels:  springframework
docker-api-graphql
GraphQL API wrapper around the Docker Remote API. SpringBoot-based app, written in Kotlin
Stars: ✭ 13 (-69.05%)
Mutual labels:  springframework
anime-for-dev
A curated list of animes every developer should watch.
Stars: ✭ 95 (+126.19%)
Mutual labels:  curated-list
tutorials
Code samples for tutorials blog
Stars: ✭ 49 (+16.67%)
Mutual labels:  springframework
Spring5Certification
Spring Certification: This repository contains my examples and some best references to prepare the Spring 5 certification
Stars: ✭ 30 (-28.57%)
Mutual labels:  springframework
kotlin-postgres
A Simple CRUD API using Spring Boot Application using PostgreSQL Database
Stars: ✭ 20 (-52.38%)
Mutual labels:  springframework
gro-light-automation
A raspberry pi project to automate hydroponics with relays and data sensors through a web application
Stars: ✭ 44 (+4.76%)
Mutual labels:  springframework
extdirectspring-demo
Sample applications for ExtDirectSpring
Stars: ✭ 18 (-57.14%)
Mutual labels:  springframework
links-uteis
📎 A curated list of awesome project development links
Stars: ✭ 2,547 (+5964.29%)
Mutual labels:  curated-list
osint-notes
Good info about DeepWeb and OSINT
Stars: ✭ 24 (-42.86%)
Mutual labels:  curated-list
firefox-extensions
Awesome Firefox Extensions
Stars: ✭ 40 (-4.76%)
Mutual labels:  curated-list
spring-data-jdbc-repository
Spring Data JDBC generic DAO implementation in Java (more up-to-date fork)
Stars: ✭ 123 (+192.86%)
Mutual labels:  springframework
Trump-Driven-Development
A curated list of Trump Driven Development
Stars: ✭ 15 (-64.29%)
Mutual labels:  curated-list
awesome-macos-apps
Curated list of awesome macOS apps
Stars: ✭ 13 (-69.05%)
Mutual labels:  curated-list
clojure-spring-cloud
Clojure Spring Cloud Sample
Stars: ✭ 33 (-21.43%)
Mutual labels:  springframework
Awesome NFTs
A curated collection about NFTs - by bt3gl
Stars: ✭ 42 (+0%)
Mutual labels:  curated-list
Glitch-Arts-Resources
A curated list of resources for all arts glitch.
Stars: ✭ 86 (+104.76%)
Mutual labels:  curated-list

List of frequently used annotations in Spring Boot apps

PRs Welcome license

This document contains non-comprehensive list of frequently used annotations in Spring Boot applications. It should rather be used as a quick lookup list, for detailed and comprehensive information please read official javadocs and documentation.

Contents

Core Spring

  • @Bean - Annotated method produces a bean managed by the Spring IoC container
  • Stereotype annotations
    • @Component - Marks annotated class as a bean found by the component-scanning and loaded into the application context
    • @Controller - Marks annotated class as a bean for Spring MVC containing request handler
    • @RestController - Marks annotated class as a @Controller bean and adds @ResponseBody to serialize returned results as messages
    • @Configuration - Marks annotated class as a Java configuration defining beans
    • @Service - Marks annotated class as a bean (as convention usually containing business logic)
    • @Repository - Marks annotated class as a bean (as convention usually providing data access) and adds auto-translation from SQLException to DataAccessExceptions

Bean state

  • @PostConstruct - Annotated method is executed after dependency injection is done to perform initialization
  • @PreDestroy - Annotated method is executed before the bean is destroyed, e.g. on the shutdown

Configuration

  • @Import - Imports one or more Java configuration classes @Configuration
  • @PropertySource - Indicates the location of applicaiton.properties file to add key-value pairs to Spring Environment
  • @Value - Annotated fields and parameters values will be injected
  • @ComponentScan - Configures component scanning @Compenent, @Service, etc.

Bean properties

Bean injection

  • @Autowired - Beans are injected into annotated setters, fields, or constructor params.
  • @Qualifier - Specifies the name of a bean as an additional condition to identify a unique candidate for autowiring

Validation

  • @Valid - Mark a property, method parameters or return type for validation
  • @Validated - Variant of @Valid that allows validation of multiple groups, e.g. all fields of an annotated class
  • @NotNull - Must be not null
  • @NotEmpty - Must be not null nor empty
  • @NotBlank - Must be not null and at least one non-whitespace character
  • @Digits - Must be a number within accepted range
  • @Past - Must be an instant, date or time in the past
  • @Future - Must be an instant, date or time in the future
  • ...

Spring Boot

Spring Boot Tests

  • @SpringBootTest - Annotated test class will load the entire application context for integration tests
  • @WebMvcTest - Annotated test class will load only the web layer (service and data layer are ignored)
  • @DataJpaTest - Annotated class will load only the JPA components
  • @MockBean - Marks annotated field as a mock and loads it as a bean into the application context
  • @SpyBean - Allows partial mocking of beans
  • @Mock - Defines annotated field as a mock

Spring Test

  • @ContextConfiguration - Defines @Configuration to load application context for integration test
  • @ExtendWith - Defines extensions to execute the tests with, e.g. MockitoExtension
  • @SpringJUnitConfig - Combines @ContextConfiguration and @ExtendWith(SpringExtension.class)
  • @TestPropertySource - Defines the location of property files used in integration tests
  • @DirtiesContext - Indicates that annotated tests dirty the application context and will be cleaned after each test
  • @ActiveProfiles - Defines which active bean definition should be loaded when initializing the test application context
  • @Sql - Allows defining SQL scripts and statements to be executed before and after tests

Transactions

Spring JPA and Hibernate

  • @Id - Marks annotated field as a primary key of an entity
  • @GeneratedValue - Provides generation strategy of primary keys
  • @Entity - Marks annotated class as an entity
  • @Column - Provides additional configuration for a field, e.g. column name
  • @Table - Provides additional configuration for an entity, e.g. table name
  • @PersistenceContext - EntityManger is injected into annotated setters and fields
  • @Embedded - Annotated field is instantiated as a value of an Embeddable class
  • @Embeddable - Instances of an annotated class are stored as part of an entity
  • @EmbeddedId - Marks annotated property as a composite key mapped by an embeddable class
  • @AttributeOverride - Overrides the default mapping of a field
  • @Transient - Annotated field is not persistent
  • @CreationTimestamp - Annotated field contains the timestamp when an entity was stored for the first time
  • @UpdateTimestamp - Annotated field contains the timestamp when an entity was updated last time
  • @ManyToOne - Indicates N:1 relationship, the entity containing annotated field has a single relation to an entity of other class, but the other class has multiple relations
  • @JoinColumn - Indicates a column for joining entities in @ManyToOne or @OneToOne relationships at the owning side or unidirectional @OneToMany
  • @OneToOne - Indicates 1:1 relationship
  • @MapsId - References joining columns of owning side of @ManyToOne or @OneToOne relationships to be the primary key of referencing and referenced entities
  • @ManyToMany - Indicates N:M relationship
  • @JoinTable - Specifies an association using a join table
  • @BatchSize - Defines size to lazy load a collection of annotated entities
  • @FetchMode - Defines fetching strategy for an association, e.g. loading all entities in a single subquery

Spring Security

  • @EnableWebSecurity - Enables web security
  • @EnableGlobalMethodSecurity - Enables method security
  • @PreAuthorize - Defines access-control expression using SpEL, which is evaluated before invoking a protected method
  • @PostAuthorize - Defines access-control expression using SpEL, which is evaluated after invoking a protected method
  • @RolesAllowed - Specifies a list of security roles allowed to invoke protected method
  • @Secured - Java 5 annotation for defining method level security

Spring AOP

  • @EnableAspectJAutoProxy - Enables support for handling components marked with @Aspect
  • @Aspect - Declares an annotated component as an aspect containing pointcuts and advices
  • @Before - Declares a pointcut executed before the call is propagated to the join point
  • @AfterReturning - Declares a pointcut executed if the join point successfully returns a result
  • @AfterThrowing - Declares a pointcut executed if the join point throws an exception
  • @After - Declares a pointcut executed if the join point successfully returns a result or throws an exception
  • @Around - Declares a pointcut executed before the call giving control over the execution of the join point to the advice
  • @Pointcut - Externalized definition a pointcut expression
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].