GithubHelp home page GithubHelp logo

rameshmf / all-spring-and-spring-boot-annotations Goto Github PK

View Code? Open in Web Editor NEW
24.0 2.0 6.0 4 KB

Check out all the spring core, spring MVC, spring boot, spring cloud, spring data jpa annotations with examples, tutorials, andguides.

all-spring-and-spring-boot-annotations's Introduction

List of Spring Framework and Spring Boot Annotations

Check out all the spring core, spring MVC, spring boot, spring cloud, and spring data jpa annotations with examples, tutorials, and guides. Click on each annotation to learn in-depth with examples. I will continue adding more annotations here.

1. Spring Core Annotations

@Component Annotation : The @Component annotation indicates that an annotated class is a “spring bean/component”. The @Component annotation tells the Spring container to automatically create Spring bean.

@Autowired Annotation : The @Autowired annotation is used to inject the bean automatically. The @Autowired annotation is used in constructor injection, setter injection, and field injection

@Qualifier Annotation : @Qualifier annotation is used in conjunction with Autowired to avoid confusion when we have two or more beans configured for the same type.

@Primary Annotation : We use @Primary annotation to give higher preference to a bean when there are multiple beans of the same type.

@Bean Annotation : @Bean annotation indicates that a method produces a bean to be managed by the Spring container. The @Bean annotation is usually declared in the Configuration class to create Spring Bean definitions.

@Lazy Annotation : By default, Spring creates all singleton beans eagerly at the startup/bootstrapping of the application context. You can load the Spring beans lazily (on-demand) using @Lazy annotation.

@Scope Annotation : The @Scope annotation is used to define the scope of the bean. We use @Scope to define the scope of a @Component class or a @Bean definition. 

@Value Annotation : Spring @Value annotation is used to assign default values to variables and method arguments.

@PropertySource Annotation : Spring @PropertySource annotation is used to provide properties files to Spring Environment. Spring PropertySource annotation is repeatable, which means you can have multiple PropertySource on a Configuration class.

2. Spring MVC Web Annotations

@Controller Annotation : Spring provides @Controller annotation to make a Java class as a Spring MVC controller. The @Controller annotation indicates that a particular class serves the role of a controller. 

@ResponseBody Annotation : The @ResponseBody annotation tells a controller that the object returned is automatically serialized into JSON and passed back into the HttpResponse object. 

@RestController Annotation : Spring 4.0 introduced @RestController, a specialized version of the @Controller which is a convenience annotation that does nothing more than add the @Controller and @ResponseBody annotations. 

@RequestMapping Annotation : @RequestMapping is the most common and widely used annotation in Spring MVC. It is used to map web requests onto specific handler classes and/or handler methods. 

@GetMapping Annotation : The GET HTTP request is used to get single or multiple resources and @GetMapping annotation for mapping HTTP GET requests onto specific handler methods. 

@PostMapping Annotation : The POST HTTP method is used to create a resource and @PostMapping annotation for mapping HTTP POST requests onto specific handler methods. 

@PutMapping Annotation : The PUT HTTP method is used to update the resource and @PutMapping annotation for mapping HTTP PUT requests onto specific handler methods. 

@DeleteMapping Annotation : The DELETE HTTP method is used to delete the resource and @DeleteMapping annotation for mapping HTTP DELETE requests onto specific handler methods. 

@PatchMapping Annotation : The PATCH HTTP method is used to update the resource partially and the @PatchMapping annotation is for mapping HTTP PATCH requests onto specific handler methods.

@PathVariable Annotation : Spring boot @PathVariable annotation is used on a method argument to bind it to the value of a URI template variable.

@ResponseStatus Annotation : The @ResponseStatus annotation is a Spring Framework annotation that is used to customize the HTTP response status code returned by a controller method in a Spring MVC or Spring Boot application.

@Service Annotation : @Service annotation is used to create Spring beans at the Service layer.

@Repository Annotation : @Repository is used to create Spring beans for the repositories at the DAO layer.

@Controller Annotation : @Controller is used to create Spring beans at the controller layer.

3. Spring Boot Annotations

@SpringBootApplication annotation : The @SpringBootApplication annotation is a core annotation in the Spring Boot framework. It is used to mark the main class of a Spring Boot application. This annotation is a combination of three other annotations: @Configuration, @EnableAutoConfiguration, and @ComponentScan.

@EnableAutoConfiguration annotation : @EnableAutoConfiguration annotation enables Spring Boot's auto-configuration feature, which automatically configures the application based on the classpath dependencies and the environment. 

@Async Annotation : @Async annotation can be provided on a method so that invocation of that method will occur asynchronously.

4. Spring Data JPA Annotations

@Query Annotation : In Spring Data JPA, the @Query annotation is used to define custom queries. It allows developers to execute both JPQL (Java Persistence Query Language) and native SQL queries.

5. Spring Boot Testing Annotations

@SpringBootTest annotation : Spring Boot provides @SpringBootTest annotation for Integration testing. This annotation creates an application context and loads the full application context.

@DataJpaTest annotation : Spring Boot provides the @DataJpaTest annotation to test the persistence layer components that will autoconfigure the in-memory embedded database for testing purposes.

@WebMvcTest annotation :The @WebMvcTest annotation is used to perform unit tests on Spring MVC controllers. It allows you to test the behavior of controllers, request mappings, and HTTP responses in a controlled and isolated environment.

all-spring-and-spring-boot-annotations's People

Contributors

rameshmf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.