Tag: Spring Annotations

Spring

Spring @Value Annotation

Introduction: Spring @Value annotation is used to inject values into variables and method arguments. We can either read spring environment variables or system variables. It also supports SpEL. In this quick tutorial, we’ll explore how to work with Spring @Value annotation. Setup: Let’s start by first defining a few properties in our app.properties file:

[…]

Be the First to comment. Read More
Spring

Spring MVC Annotations

Introduction: Spring 2.5 onwards, we can use annotations to mark our Spring components. One way of doing so is to use a <component-scan> tag in our appConfig.xml:

The Spring container will then recursively scan all components in the given package & its sub-packages. In this quick tutorial, we’ll discuss the most commonly used Spring […]

3 comments Read More
Spring

Using @ResponseStatus for Http Status in Spring

Introduction: In Spring MVC, we can set the status of the HttpResponse in several ways. In this tutorial, we’ll achieve it using the @ResponseStatus annotation. We can use @ResponseStatus to mark a method or an exception class with a status code and reason that should be returned. On invoking the marked handler method or when […]

Be the First to comment. Read More
Spring

@Component vs @Repository vs @Service in Spring

Introduction: With Spring’s auto-scanning feature, it automatically detects various beans defined in our application. We usually annotate our beans using one of the available Spring annotations – @Component, @Repository, @Service, @Controller. On detecting the bean, Spring simply registers it into the ApplicationContext. In this quick tutorial, we’ll look at the difference between @Component, @Repository, and, […]

Be the First to comment. Read More
Spring

Spring Core Annotations

Introduction: Spring annotations present in the org.springframework.beans.factory.annotation andĀ org.springframework.context.annotation packages are commonly known as Spring Core annotations. We can divide them into two broad categories: DI-Related Annotations & Context Configuration Annotations:     In this tutorial, we’ll explore all of these Spring Core annotations. DI-Related Annotations: 1. @Autowired: We use @Autowired to mark the dependency which […]

One comment Read More
Spring

Spring MVC @Controller vs @RestController Annotation

Introduction: In this tutorial, we’ll look at the difference between @Controller and @RestController annotations in Spring MVC. The @Controller annotation has been part of the Spring framework from the very beginning. As its name suggests, it defines a controller: an entry-point for a Spring Web application. Spring 4 introduced a @RestController annotation. It is a […]

One comment Read More