<?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>DEV Community: Sri </title>
    <description>The latest articles on DEV Community by Sri  (@s_srikamini_bfb9ce2df10).</description>
    <link>https://dev.to/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>DEV Community: Sri </title>
      <link>https://dev.to/s_srikamini_bfb9ce2df10</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/s_srikamini_bfb9ce2df10"/>
    <language>en</language>
    <item>
      <title>Spring Security</title>
      <dc:creator>Sri </dc:creator>
      <pubDate>Tue, 19 May 2026 13:01:09 +0000</pubDate>
      <link>https://dev.to/s_srikamini_bfb9ce2df10/spring-security-4n7k</link>
      <guid>https://dev.to/s_srikamini_bfb9ce2df10/spring-security-4n7k</guid>
      <description>&lt;p&gt;Spring security provides authentication an authorisation.&lt;br&gt;
Spring Security is a security framework for Java and Spring Boot applications.&lt;/p&gt;

&lt;p&gt;It provides:&lt;/p&gt;

&lt;p&gt;Authentication → verifying user identity&lt;br&gt;
Authorization → controlling access&lt;br&gt;
Session management&lt;br&gt;
Password encryption&lt;br&gt;
CSRF protection&lt;br&gt;
JWT/OAuth2 support&lt;br&gt;
Spring security will be enabled after adding below XML defintions in POM.xml.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
org.springframework.boot&lt;br&gt;
spring-boot-starter-security&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
org.springframework.boot&lt;br&gt;
spring-boot-starter-security-test&lt;br&gt;
test&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Spring security filters almost all pages except the pages which is marked to permit and gives login page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Type 1:&lt;/strong&gt;&lt;br&gt;
Passwor will be automatically generate in devleoper tool console and user will be user.&lt;br&gt;
This password will be changedd on each application bootup.&lt;br&gt;
Flow :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://localhost:8080/First/add/6/8" rel="noopener noreferrer"&gt;http://localhost:8080/First/add/6/8&lt;/a&gt;&lt;br&gt;
when the user clicks this link, instead of displaying output a login page will be shown, this is prewritten and plugged in using xml definition. the actual output of addition will be displayed after authentication.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Type:2&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Adding our own username and password in application properties.&lt;br&gt;
spring.security.user.name=admin&lt;br&gt;
spring.security.user.password=generate&lt;br&gt;
Now application will not generate password but a login page will be shown on clicking the addition endpoint.&lt;br&gt;
User has to enter correct username and password mentioned in application.properties. After authenticating him, he will be redirected to the output page,else error with status code 403 will be displayed&lt;br&gt;
&lt;strong&gt;Type3:&lt;/strong&gt;&lt;br&gt;
Adding multiple users.&lt;br&gt;
we cannot add all users in property file. Though property file will not accept adding duplicate properties, in real time we will be having huge data  and adding in property or convincing it to accept is not an idea.&lt;/p&gt;

&lt;p&gt;So we can achieve this multiple user concept in spring security using UserDetailsManager Interface. Its implementation class is InMemoryUserDetailsManager.&lt;br&gt;
This accepts a list with userDetails objects.&lt;br&gt;
UserDetails is a static method with methods to add username,password,roles etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is the code snippet:&lt;/strong&gt;&lt;br&gt;
@Configuration&lt;br&gt;
@EnableWebSecurity&lt;br&gt;
public class SecurityConfig {&lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/bean"&gt;@bean&lt;/a&gt;&lt;br&gt;
 public UserDetailsManager createUserDetailsManager(){&lt;/p&gt;

&lt;p&gt;UserDetails user1= User.withUsername("Sri").password("{noop}generate").roles("admin").build();&lt;br&gt;
UserDetails user2=User.withUsername("Desigan").password("{noop}generate").roles("user").build();&lt;br&gt;
        // Add users to the UserDetailsManager&lt;br&gt;
List l =   Arrays.asList(user1, user2);&lt;br&gt;
UserDetailsManager userDetailsManager = new InMemoryUserDetailsManager(l);&lt;br&gt;
return userDetailsManager;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorisation:&lt;/strong&gt;&lt;br&gt;
It works based on user privilages.&lt;br&gt;
User with admin access can see all pages.&lt;br&gt;
User with read access can view pages but he cannot make any changes.&lt;br&gt;
we can set these privilages in security config class.&lt;/p&gt;

&lt;p&gt;&lt;a class="mentioned-user" href="https://dev.to/bean"&gt;@bean&lt;/a&gt;&lt;br&gt;
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    http
       // Disable CSRF (useful for REST APIs)
            .csrf(csrf -&amp;gt; csrf.disable())

       // Authorization rules
 .authorizeHttpRequests(auth -&amp;gt; auth
 .requestMatchers("/calc/add/**").permitAll()   // No auth required
 .requestMatchers("/calc/sub/**").hasRole("USER")
 .requestMatchers("/calc/mul/**").hasRole("ADMIN")
 .requestMatchers("/calc/div/**").hasRole("ADMIN")
 .anyRequest().authenticated()
            )
 .formLogin(Customizer.withDefaults());

    return http.build();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In above snippet ".permitAll()" allows the user to view endpoint without any authentication.&lt;br&gt;
For all the requestMatchers("/div/&lt;strong&gt;").hasRole("user") -&amp;gt; user with User role will be able to view this page.&lt;br&gt;
**Option 2: JDBCUserDetialsManager.&lt;/strong&gt;&lt;br&gt;
It is nothing but communicating with database to perform login.&lt;br&gt;
It has four steps, 1. collect data from UI 2. Request Database for UserDetails using loadByUserName(username) method from UserDetailService interface.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;compare data from UI with data from DB&lt;/li&gt;
&lt;li&gt;Provide success or failure login based on the results from above step.
To achieve this we need load data into DB first, This is what we call as "SIGNUP".
Im going to write an endpoint and send a request from POSTMan and load data into Database. This request again pass through Spring security firewall check. To allow our request to endpoint we can request spring security to permit our endpoint URL by adding below line.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http.csrf(csrf -&amp;gt; csrf.disable())

            .authorizeHttpRequests(auth -&amp;gt; auth
             .requestMatchers("/", "/error").permitAll()
             .requestMatchers("/First/signUp/**").permitAll()
             .anyRequest().authenticated())
            .formLogin(Customizer.withDefaults());
           // .httpBasic(Customizer.withDefaults());

    return http.build();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Controller:&lt;/strong&gt;&lt;br&gt;
    @RequestMapping("/signUp")&lt;br&gt;
    ////@ResponseBody&lt;br&gt;
    public ResponseEntity processUserSignUp(@RequestBody User user ){&lt;br&gt;
        log.info("inside LearningFrontController.getmultiplyService");&lt;br&gt;
        response=calculatorService.processUserSignUp(user);&lt;br&gt;
        log.info(response);&lt;br&gt;
        if(response.equalsIgnoreCase("success")){&lt;br&gt;
            return ResponseEntity.status(200).body(response);&lt;br&gt;
        }&lt;br&gt;
        log.info("exiting LearningFrontController.getmultiplyService");&lt;br&gt;
        return ResponseEntity.status(400).body("Signup failed");&lt;br&gt;
    }&lt;br&gt;
&lt;strong&gt;Service:&lt;/strong&gt;&lt;br&gt;
 public String processUserSignUp(User user){&lt;br&gt;
       String response="failed";&lt;br&gt;
       UserDetailsEntity userDetailsEntity = new UserDetailsEntity();&lt;br&gt;
       userDetailsEntity.setUserName(user.getUserName());&lt;br&gt;
       String maskedPassword=passwordEncoder.encode(user.getPassword());&lt;br&gt;
       userDetailsEntity.setMaskedPassword(maskedPassword);&lt;br&gt;
       userDetailsEntity.setUserRole(user.getRoles());&lt;br&gt;
UserDetailsEntity userDetailsEntity1=   customUserDetailsRepo.save(userDetailsEntity);&lt;br&gt;
                if(userDetailsEntity1!=null) {&lt;br&gt;
                    return "success";&lt;br&gt;
                }&lt;br&gt;
            return response;&lt;br&gt;
        }&lt;br&gt;
JSON:&lt;/p&gt;

&lt;p&gt;{&lt;br&gt;
    "userName":"Sri",&lt;br&gt;
    "Password":"generate",&lt;br&gt;
    "roles":"User"&lt;br&gt;
}&lt;br&gt;
What we have in table?&lt;br&gt;
&lt;strong&gt;UserNo   PAssword                            userName        Role&lt;/strong&gt;&lt;br&gt;
202    $2a$10$PtbhgrteGOLk0azcyGK1x       SriKamini         USER&lt;br&gt;
203    $2a$10$WcefaBSrdqTIqLLOAh3XNep   Sri         USER&lt;/p&gt;

</description>
      <category>backend</category>
      <category>java</category>
      <category>security</category>
      <category>springboot</category>
    </item>
    <item>
      <title>Spring Annotations Part2</title>
      <dc:creator>Sri </dc:creator>
      <pubDate>Thu, 16 Apr 2026 18:37:49 +0000</pubDate>
      <link>https://dev.to/s_srikamini_bfb9ce2df10/spring-annotations-part2-1aj5</link>
      <guid>https://dev.to/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://dev.to/s_srikamini_bfb9ce2df10/springboot-basic-annotations-and-logging-11ci</link>
      <guid>https://dev.to/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>
