<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sri </title>
    <description>The latest articles on Forem by Sri  (@s_srikamini_bfb9ce2df10).</description>
    <link>https://forem.com/s_srikamini_bfb9ce2df10</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3868750%2Fcf1f8f04-508b-4e05-9ac2-2e6cf7d82124.webp</url>
      <title>Forem: Sri </title>
      <link>https://forem.com/s_srikamini_bfb9ce2df10</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/s_srikamini_bfb9ce2df10"/>
    <language>en</language>
    <item>
      <title>Spring Annotations Part2</title>
      <dc:creator>Sri </dc:creator>
      <pubDate>Thu, 16 Apr 2026 18:37:49 +0000</pubDate>
      <link>https://forem.com/s_srikamini_bfb9ce2df10/spring-annotations-part2-1aj5</link>
      <guid>https://forem.com/s_srikamini_bfb9ce2df10/spring-annotations-part2-1aj5</guid>
      <description>&lt;p&gt;&lt;strong&gt;@Restcontrolleradvice **&lt;br&gt;
A convenience annotation that combines @ControllerAdvice and @ResponseBody. It is designed for RESTful APIs where the return value of an exception handler is automatically serialized into the response body (typically as JSON or XML) instead of being resolved as a view.&lt;br&gt;
**@ExceptionHandler&lt;/strong&gt;&lt;br&gt;
We can use @ExceptionHandler to annotate methods that Spring automatically invokes when the given exception occurs. We can specify the exception either with the annotation or by declaring it as a method parameter, which allows us to read out details from the exception object to handle it correctly. The method itself is handled as a Controller method.&lt;br&gt;
EX:&lt;br&gt;
@RestControllerAdvice&lt;br&gt;
public class ExceptionController {&lt;br&gt;
    @ExceptionHandler(NullPointerException.class)&lt;br&gt;
     public String hanleNullPointerException(NullPointerException ex){&lt;br&gt;
         return "Error: "+ex.getMessage();&lt;br&gt;
     }&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@ExceptionHandler(MethodArgumentNotValidException.class)
public String hanleIllegalArgumentException(MethodArgumentNotValidException ex){
    return "Error: "+ex.getMessage();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}&lt;br&gt;
&lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/valid"&gt;@valid&lt;/a&gt;:&lt;/strong&gt;&lt;br&gt;
It informs controller about the presence of @ExceptionHandler.&lt;br&gt;
When an exception occurs,Spring container redirects the flow to corresponding Exception handler method&lt;br&gt;
@PostMapping("/SaveBookDetails")&lt;br&gt;
    public String SaveBookDetails(@RequestBody &lt;a class="mentioned-user" href="https://dev.to/valid"&gt;@valid&lt;/a&gt; BookDetails bookDetails) {&lt;br&gt;
        log.info("entering ProcessBookDetailsController");&lt;br&gt;
        String ValueFromService=bookService.SaveBookDetails(bookDetails);&lt;br&gt;
        log.info("leaving ProcessBookDetailsController");&lt;br&gt;
    return ValueFromService;&lt;br&gt;
    }&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To Enable validations in coding we have Spring Boot validation dependency.&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;For Spring Boot applications,&lt;/strong&gt; the standard dependency for enabling Bean Validation is spring-boot-starter-validation. This starter provides the Jakarta Bean Validation API and Hibernate Validator as the default implementation. &lt;br&gt;
&lt;strong&gt;Enabling Validation&lt;/strong&gt;: Once the dependency is added, you must use annotations such as &lt;a class="mentioned-user" href="https://dev.to/valid"&gt;@valid&lt;/a&gt; or @Validated on your controller method parameters (e.g., @RequestBody) to trigger the validation process.&lt;br&gt;
Standard Annotations: The dependency supports standard JSR-380 annotations including @NotNull, &lt;a class="mentioned-user" href="https://dev.to/notblank"&gt;@notblank&lt;/a&gt;, @Size, &lt;a class="mentioned-user" href="https://dev.to/min"&gt;@min&lt;/a&gt;, &lt;a class="mentioned-user" href="https://dev.to/max"&gt;@max&lt;/a&gt;, and @Email.&lt;br&gt;
&lt;strong&gt;Historical Note&lt;/strong&gt;: Starting with Spring Boot 2.3, the validation starter is no longer included by default in spring-boot-starter-web or spring-boot-starter-webflux. You must add it explicitly to your project.&lt;br&gt;
Error Handling: When validation fails, Spring Boot typically throws a MethodArgumentNotValidException, which can be captured using a Global Exception Handler with @ControllerAdvice. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pom.xml&lt;/strong&gt;&lt;br&gt;
Dependency Configurations&lt;br&gt;
&lt;br&gt;
org.springframework.boot&lt;br&gt;
spring-boot-starter-validation&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
org.springframework.boot&lt;br&gt;
spring-boot-starter-validation-test&lt;br&gt;
test&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Code:&lt;br&gt;
package LiBrary;&lt;/p&gt;

&lt;p&gt;import jakarta.validation.constraints.*;&lt;/p&gt;

&lt;p&gt;public class BookDetails {&lt;br&gt;
    @NotEmpty&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String bookName;

@NotNull
@Positive
@Min(0)
@Max(50)
int bookId;
double price;

@NotBlank
@NotEmpty
String authorName;
String Genre;
@Email
String email;

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public double getPrice() {
    return price;
}

public void setPrice(double price) {
    this.price = price;
}

public String getBookName() {
    return bookName;
}

public void setBookName(String bookName) {
    this.bookName = bookName;
}

public int getBookId() {
    return bookId;
}

public void setBookId(int bookId) {
    this.bookId = bookId;
}

public String getGenre() {
    return Genre;
}

public void setGenre(String genre) {
    Genre = genre;
}

public String getAuthorName() {
    return authorName;
}

public void setAuthorName(String authorName) {
    this.authorName = authorName;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Setting default error message for valid annotations:&lt;br&gt;
 @NotEmpty(message="bookname cannot be blank")&lt;br&gt;
    String bookName;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@NotNull(message="Book id cannot be null")
@Positive(message="Book Id must be +ve")
@Min(0)
@Max(50)
int bookId;
double price;

@NotBlank(message="author name cannot be blank")
@NotEmpty(message="author name cannot be empty")
String authorName;
String Genre;
@Email(message="Not a valid email address")
String email;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;error message:&lt;br&gt;
arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [bookDetails.bookId,bookId]; arguments []; default message [bookId]]; default message [&lt;strong&gt;Book Id must be +ve&lt;/strong&gt;]] [Field error in object 'bookDetails' on field 'authorName': rejected value [ ]; codes [NotBlank.bookDetails.authorName,NotBlank.authorName,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ResponseEntity:&lt;/strong&gt;&lt;br&gt;
ResponseEntity is a class in the Spring Framework used to represent the entire HTTP response. Unlike simply returning an object, it allows developers to fully configure the status code, headers, and response body sent back to the client. &lt;br&gt;
It can be any objectlike List, Map or user define class&lt;/p&gt;

&lt;p&gt;1.public class ResponseEntity extends HttpEntity&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Extension of HttpEntity that adds an HttpStatusCode status code. Used in RestTemplate as well as in @Controller methods.
3.In RestTemplate, this class is returned by getForEntity() and exchange():
&lt;strong&gt;Snippet 1:&lt;/strong&gt;
ResponseEntity entity = template.getForEntity("&lt;a href="https://example.com" rel="noopener noreferrer"&gt;https://example.com&lt;/a&gt;", String.class);
String body = entity.getBody();
MediaType contentType = entity.getHeaders().getContentType();
HttpStatus statusCode = entity.getStatusCode();
&lt;strong&gt;Snippet 2&lt;/strong&gt;
public ResponseEntity hanleIllegalArgumentException(MethodArgumentNotValidException ex){
    Map errors=new HashMap();
    //Code Snippet 1 - displays only key error message
    ex.getBindingResult().getFieldErrors().forEach(Error-&amp;gt;{
        errors.put(Error.getField(),Error.getDefaultMessage());
    });
    return new ResponseEntity("validation error "+errors , HttpStatusCode.valueOf(400));
    //Code Snippet 2 - displays all error with vast data
   // return new ResponseEntity("validation error "+ex.getMessage() , HttpStatusCode.valueOf(400));
}
output:
validation error {authorName=author name cannot be blank, bookName=bookname cannot be blank, email=Not a valid email address, bookId=must be less than or equal to 50}&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In above snippet we returned a map. we can also return a class &lt;br&gt;
&lt;strong&gt;References:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/ResponseEntity.html" rel="noopener noreferrer"&gt;https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/ResponseEntity.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/realnamehidden1_61/what-is-the-difference-between-controlleradvice-and-restcontrolleradvice-3jf3"&gt;https://dev.to/realnamehidden1_61/what-is-the-difference-between-controlleradvice-and-restcontrolleradvice-3jf3&lt;/a&gt;
3.&lt;a href="https://www.baeldung.com/exception-handling-for-rest-with-spring" rel="noopener noreferrer"&gt;https://www.baeldung.com/exception-handling-for-rest-with-spring&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>api</category>
      <category>backend</category>
      <category>java</category>
      <category>springboot</category>
    </item>
    <item>
      <title>SpringBoot Basic Annotations and Logging</title>
      <dc:creator>Sri </dc:creator>
      <pubDate>Thu, 09 Apr 2026 12:49:38 +0000</pubDate>
      <link>https://forem.com/s_srikamini_bfb9ce2df10/springboot-basic-annotations-and-logging-11ci</link>
      <guid>https://forem.com/s_srikamini_bfb9ce2df10/springboot-basic-annotations-and-logging-11ci</guid>
      <description>&lt;p&gt;Today we learned to create a spring project in Spring initializer.&lt;br&gt;
Here we learnt metadata is data about data, some of metadata in maven is artifact,groupid and version.&lt;br&gt;
we also learned about maven project structure and adding spring web dependency. Spring web gives tomcat automatically, whereas in eclipse we as a programmer explicitly add apache tomcat server and bring it up. spring web helps to withhold tomcat server and container takes care of bringing the server up. it helps developer to concentrate on business log instead of working in bringing the server up. Its a great feature of spring boot. &lt;/p&gt;

&lt;p&gt;Exploring logs:&lt;br&gt;
application.properties&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;server.port = 8080 //port in which localhost will be accessed&lt;/li&gt;
&lt;li&gt;logging.level.root=INFO //logger prints all abstract information into the console.&lt;/li&gt;
&lt;li&gt;logging.level.root=DEBUG // It prints all debug informations.errors.and INFO into the console.&lt;/li&gt;
&lt;li&gt;logging.level.root=TRACE// It prints fine-grained logic flow.
5.logging.level.com.spring.LearningDemo = DEBUG //If we want to print only our package logs, we can do it.
6.If we want to have a external logging file in local disk we use below code in application.properties.
logging.file.name = myapp.log
logging.file.path="/E:Spring projects/LearningDemo"&lt;/li&gt;
&lt;li&gt;In production we use logging.level.root=INFO to avoid unneccesary loggings. we use DEBUG only when we want identify a bug.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;context pat is  the base URL of app. here &lt;a href="http://localhost:8080/index" rel="noopener noreferrer"&gt;http://localhost:8080/index&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Annotations:&lt;br&gt;
@Controller &lt;br&gt;
Container idetifies the mentioned class as container using this annotation.&lt;/p&gt;

&lt;p&gt;@Controller&lt;br&gt;
public class LearningFrontController {&lt;br&gt;&lt;br&gt;
    public String getResponseFromLearningFrontController(){&lt;br&gt;
       return "Welcome to SpringBootFrontController";&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
In core Java programmer has to initialise an object to call any method from one class to another. whereas in spring and spring boot container takes of creating instances, programmer can concentrate on the business logic.&lt;br&gt;
A project can have any no of controllers, we can differentiate them using requestmapping annotaion.&lt;br&gt;
@Controller&lt;br&gt;
@RequestMapping("First")&lt;br&gt;
public class LearningFrontController {&lt;br&gt;
    private static final Logger log= LoggerFactory.getLogger(LearningFrontController.class);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public String getResponseFromLearningFrontController(){
log.info("LearningFrontController started");
log.debug("Debug:LearningFrontController started");
log.debug("Debug:LearningFrontController completed");
return "Welcome to SpringBootFrontController";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;similarly  a single container can have any no of methods so we exlplicitly differentiate the method using @RequestMapping("/add")&lt;/p&gt;

&lt;p&gt;@RequestMapping("/add/{a}/{b}")&lt;br&gt;
    @ResponseBody&lt;br&gt;
    public String   getAddResponseFromLearningFrontController(@PathVariable int a,@PathVariable int b){&lt;br&gt;
        log.info("LearningFrontController started");&lt;br&gt;
        log.debug("Debug:LearningFrontController started");&lt;br&gt;
        int c=a+b;&lt;br&gt;
        log.debug("Debug:LearningFrontController completed");&lt;br&gt;
        log.debug("Debug:LearningFrontController completed");&lt;br&gt;
        return "Addition is "+c;&lt;br&gt;
    }&lt;br&gt;
This method usually returns the view name and view resolver returns it to the client but when we want to return a value and inform the container to print the returned value as content of the page, we use "@ResponseBody" &lt;br&gt;
@RequestMapping("/Login/{username}/{password}")&lt;br&gt;
        //@ResponseBody&lt;br&gt;
        public String Login(@PathVariable String username,@PathVariable String password)&lt;br&gt;
        {&lt;br&gt;
            log.debug("Debug:welcomeUser started");&lt;br&gt;
            String name1 =username;&lt;br&gt;
            log.debug("Debug:welcomeUser completed");&lt;br&gt;
            return "welcome "+username;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;@RestController &lt;br&gt;
Combination of both Responsebody and controller.&lt;br&gt;
when all methods in the container uses response body, then we can mention one annotation at the top of the controller.&lt;br&gt;
@RestController&lt;br&gt;
@RequestMapping("/second")&lt;br&gt;
public class LearningFrontREquestController {&lt;br&gt;
        private static final Logger log= LoggerFactory.getLogger(com.learning.LearningDemo.LearningFrontController.class);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public String getResponseFromLearningFrontController(){
        log.info("LearningFrontController started");
        log.debug("Debug:LearningFrontRequstController started");
        log.debug("Debug:LearningFrontrequstController completed");
        return "Welcome to SpringBootFrontController";
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Difference between Pathvariable and RequestPAram&lt;br&gt;
@PathVariable&lt;br&gt;
1.user is sending input to the method in URL.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Service will fetch this input from the url and handles in method when @Pathvariable is mentioned.&lt;/li&gt;
&lt;li&gt;URL format is http:/localhost::8080/firstControllerNameMappe/CallingMethoMap/{input1}/{input2}&lt;/li&gt;
&lt;li&gt;Its param are unique value like userid&lt;/li&gt;
&lt;li&gt;It can take only 20 arguments &amp;amp; It cannot take null values. if values are not sent in URL,it will throw 404 error.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;6.Using java.util.Optional: You can wrap the parameter in an Optional type (e.g., Optional id). If the path variable is missing from the URI, the value will be Optional.empty() rather than null.&lt;br&gt;
7.Handling with a Map: You can use a Map to capture all path variables. If a specific key is missing, its value in the map will be null.&lt;br&gt;
8.Using pathVariableOrNull (WebFlux): For applications using Spring WebFlux, the ServerRequest interface provides a pathVariableOrNull() helper method to handle missing variables gracefully.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_@RequestParam&lt;br&gt;
_&lt;/strong&gt;1. Service will receive inputs from URL &amp;amp; URL is in below format&lt;br&gt;
   &lt;a href="http://localhost:8080/firstControllerNameMappe/CallingMethoMap?input1=6&amp;amp;input2=9" rel="noopener noreferrer"&gt;http://localhost:8080/firstControllerNameMappe/CallingMethoMap?input1=6&amp;amp;input2=9&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Request can have any no of arguments &amp;amp; it wont represent unique id&lt;/li&gt;
&lt;li&gt;it usually fetches a lengthy data ex:getting all the students name starting in K. It obviusly returns n no of  data &lt;/li&gt;
&lt;li&gt;It wont take empty arguments&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;@RequestBody&lt;br&gt;
when the input is in JSON format. we use RequestBody.&lt;br&gt;
JAckson library helps to convet JSON to object inside spring boot application and it also converts the object to JSON and send it back to POSTMAN.&lt;/p&gt;

&lt;p&gt;@RequestMapping("/divide")&lt;br&gt;
    //@ResponseBody&lt;br&gt;
    public Student getDivideService(@RequestBody Student student){&lt;br&gt;
        log.info("inside LearningFrontController.getSubtractService");&lt;br&gt;
        int a=student.getFirstValue();&lt;br&gt;
        int b=student.getSecondValue();&lt;br&gt;
        log.info("a "+a +"b "+b);&lt;br&gt;
        if((a!=0)&amp;amp;&amp;amp;(b!=0)) {&lt;br&gt;
            double divided = learningDemoService.divitionService(a, b);&lt;br&gt;
            student.setDivided(divided);&lt;br&gt;
        }&lt;br&gt;
        student.setName(student.getName().toUpperCase().trim());&lt;br&gt;
        log.info(response);&lt;br&gt;
        log.info("exiting LearningFrontController.getSubtractService");&lt;br&gt;
        return student;&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Object creation:&lt;br&gt;
In java:&lt;br&gt;
To have interaction between classes we will create object using new keyword.&lt;br&gt;
Student object=new Student();&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In Spring framework.&lt;/strong&gt;&lt;br&gt;
we will declare in XML&lt;/p&gt;

&lt;p&gt;In spring boot we have two annotations&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Component &lt;/li&gt;
&lt;li&gt;Bean 
&lt;strong&gt;Component:&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;It is declared in class level. If @Comparable is mentioned on top of class, An object will be create on compile time. &lt;/li&gt;
&lt;li&gt;Auto-detected via classpath scanning.&lt;/li&gt;
&lt;li&gt;Limited; uses Spring's default instantiation.&lt;/li&gt;
&lt;li&gt;Has specialized forms: @Service, @Repository, @Controller,@Configuration. &lt;/li&gt;
&lt;li&gt;@Component is an interface&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Bean:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It is declared in Method Level. It is declared in class which has @Configuration annotation on top of it.&lt;/li&gt;
&lt;li&gt;All classe with @Configuration annotation is loaded and all the methods,construtors are loaded and all objects mentioned in the constructors are created.&lt;/li&gt;
&lt;li&gt;It can be done in three ways setter injection, field injection, constructor injection. Field injection is not advisable.&lt;/li&gt;
&lt;li&gt;programmer can have full control over the class. &lt;/li&gt;
&lt;li&gt;we can create object for third party classes using Bean even library files. 
&lt;strong&gt;Snippet 1&lt;/strong&gt;
&lt;a class="mentioned-user" href="https://dev.to/bean"&gt;@bean&lt;/a&gt;(initMethod = "init", destroyMethod = "cleanup")
public MyService myService() {
return new MyService();
}
&lt;strong&gt;Ex&lt;/strong&gt;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;@Configuration&lt;br&gt;
public class Config {&lt;br&gt;
    private static final Logger log= LoggerFactory.getLogger(Config.class);&lt;br&gt;
    &lt;a class="mentioned-user" href="https://dev.to/bean"&gt;@bean&lt;/a&gt;&lt;br&gt;
    Student getStudent(){&lt;br&gt;
        log.info("inside student Bean creation config ");&lt;br&gt;
        return new Student();&lt;br&gt;
    }&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;How it works internally&lt;br&gt;
&lt;strong&gt;Application starts:&lt;/strong&gt;&lt;br&gt;
      SpringApplication.run(MyApp.class, args);&lt;br&gt;
&lt;strong&gt;Spring Boot:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Scans classes (@ComponentScan)&lt;/li&gt;
&lt;li&gt;    Reads config (@Configuration)&lt;/li&gt;
&lt;li&gt;     Applies auto-config (@EnableAutoConfiguration)&lt;/li&gt;
&lt;li&gt;      Beans are created and stored in:&lt;/li&gt;
&lt;li&gt;👉      ApplicationContext (Spring Container&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;@PostConstruct:&lt;/strong&gt;&lt;br&gt;
we use postconstruct when we want to add values to an object immediately after initialisation.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;When it runs&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
After the bean is created and dependencies are injected&lt;br&gt;
✅ Purpose&lt;br&gt;
Initialization logic&lt;br&gt;
Setting default values&lt;br&gt;
Opening resources&lt;br&gt;
@PostConstruct&lt;br&gt;
    public void init(){&lt;br&gt;
        log.info("init method called");&lt;br&gt;
         studentFromBeanConfig.setName("Karthi");&lt;br&gt;
         studentFromBeanConfig.setLoginStatus(true);&lt;br&gt;
    }&lt;/p&gt;

&lt;p&gt;@PreDestroy&lt;br&gt;
It is used to delete values before destroying the same object.&lt;br&gt;
 @PreDestroy&lt;br&gt;
    public void preDestroy(){&lt;br&gt;
        System.out.println("Values are destroyed");&lt;br&gt;
    }&lt;br&gt;
Lifecycle of Bean :&lt;br&gt;
Bean Created → @PostConstruct → Bean in Use → @PreDestroy → Bean Destroyed&lt;/p&gt;

&lt;p&gt;Important Points for PreDestroy&lt;br&gt;
&lt;strong&gt;_Method must be:&lt;br&gt;
_&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;public&lt;/li&gt;
&lt;li&gt;void&lt;/li&gt;
&lt;li&gt;No arguments&lt;/li&gt;
&lt;li&gt;Works only for singleton beans by default&lt;/li&gt;
&lt;li&gt;Triggered when:
    Application stops
    Context is closed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;a class="mentioned-user" href="https://dev.to/primary"&gt;@primary&lt;/a&gt; &amp;amp; @Qualifier&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
In Spring and Spring Boot, both &lt;a class="mentioned-user" href="https://dev.to/primary"&gt;@primary&lt;/a&gt; and @Qualifier are used to resolve autowiring ambiguity when multiple beans of the same type exist in the application context.&lt;br&gt;
&lt;strong&gt;Primary Annotation:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;a class="mentioned-user" href="https://dev.to/primary"&gt;@primary&lt;/a&gt; annotation in Spring is used to designate a primary bean among multiple beans of the same type. When a primary bean is defined using &lt;a class="mentioned-user" href="https://dev.to/primary"&gt;@primary&lt;/a&gt;, it is preferred for injection when no specific bean name or qualifier is provided.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;this is a class level annotation&lt;br&gt;
&lt;strong&gt;Qualifier Annotation:&lt;/strong&gt;&lt;br&gt;
On the other hand, the @Qualifier annotation is used to specify the exact bean to be injected when multiple beans of the same type are present. It works in conjunction with bean names or custom qualifiers to resolve ambiguity and specify the desired bean for injection.&lt;br&gt;
Example:&lt;br&gt;
@RestController&lt;br&gt;
@RequestMapping("student")&lt;br&gt;
public class StudentPrimaryAndQualiferService {&lt;br&gt;
@Autowired&lt;br&gt;
@Qualifier("JavaCoursestuent")&lt;br&gt;
StudentInterface studentInterface;&lt;/p&gt;

&lt;p&gt;@RequestMapping("/getStudentInferface")&lt;br&gt;
public String getStudentInterface(){&lt;br&gt;
    return "Name: "+studentInterface.getName()+ "Roll No :" +studentInterface.getRollNo();&lt;br&gt;
}&lt;br&gt;
}&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;package LearningBeanConfig;&lt;/p&gt;

&lt;p&gt;import org.springframework.context.annotation.Primary;&lt;br&gt;
import org.springframework.stereotype.Component;&lt;/p&gt;

&lt;p&gt;@Component&lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/primary"&gt;@primary&lt;/a&gt;&lt;br&gt;
public class SchoolStudent implements StudentInterface{&lt;br&gt;
    &lt;a class="mentioned-user" href="https://dev.to/override"&gt;@override&lt;/a&gt;&lt;br&gt;
    public String getName() {&lt;br&gt;
        return "SchoolStudent";&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Override
public String getRollNo() {
    return "DAV-11";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;package LearningBeanConfig;&lt;/p&gt;

&lt;p&gt;import com.Learning.LearningDemo.LearningDemoApplication;&lt;br&gt;
import org.slf4j.Logger;&lt;br&gt;
import org.slf4j.LoggerFactory;&lt;br&gt;
import org.springframework.stereotype.Component;&lt;/p&gt;

&lt;p&gt;@Component(value="JavaCoursestuent")&lt;br&gt;
public class JavaCourseStu implements StudentInterface {&lt;br&gt;
    private static final Logger log = LoggerFactory.getLogger(JavaCourseStu.class);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Override
public String getName() {
    log.info("JavaCoursestuent.getNAme starts");
    return "Java Course StudentInterface ";
}

@Override
public String getRollNo() {
    log.info("JavaCoursestuent.getRollNo starts");
    return "RollNo1";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

</description>
      <category>backend</category>
      <category>beginners</category>
      <category>java</category>
      <category>springboot</category>
    </item>
  </channel>
</rss>
