Spring Boot:

Spring boot is used for production grade applications.

What is run method in spring boot?

  • It starts the stopwatch to identify to time taken used by bootstrap f your server

  • It set the ConfigurableApplicationContext to null

  • Create an array list to store the error in the application at startup [SpringbootExceptionRepoter]

  • Then they getting the listeners

  • Then loading default application arguments

  • And they prepare environment for the springboot application

  • Call print Banner method [we can pass your own banner and we can off the banner]

  • Preparing the Application context

  • This springboot uses any one of these three type of the application context [ servlet, reactive and default (AnnotationConfigurableApplicationContext class is used)]

  • And it calls BeanUtils the class which is loaded it will crrate the bean

  • Return type of run() is ConfigurableApplicationContext

  • Stop the stopwatch

  • And calls runner in sprinboot we have applicationrunners and commandlinerunners

  • finally, it returns the context.

  • Use ConfigurableApplicationContext with SpringApplication.run() in Spring Boot applications to leverage auto-configuration and lifecycle management.

  • Use AnnotationConfigApplicationContext when you want a more lightweight context without Spring Boot’s auto-configuration, typically for unit tests, modular setups, or non-Spring Boot contexts.


@Required:
   - it primary uses for the setting the bean property  via dependecy injection,if we not set or during  bean initialization then  Spring Boot will throw an exception indicating the missing required property.
   - it uses in validation,configuation.

@Autowired:
   - it is used to peform dependecy injection 
@Configuartion:
   - it represent our class as configuration class,it bascially use on the classs levl annotation

@ComponentScan: 
   - it is  aclass level annoation, it scans the packages and sub packages, to automatically discover Spring-managed components such as beans, controllers, services, etc
@Bean:
   - It is method level annotation which is use dto repsent our method as a spring bean 
      and for customise bean we use.
@Qualifier:
  - it specifies when multiples beans are present which bean is to inject.
@Lazy:
  - this represents   Spring is used to delay the initialization of a bean until the bean is first requested. This means that the bean will not be instantiated during the application's startup phase but will be created only when it is needed.  
@Value:
  -Injects values from properties files, environment variables, or other sources into bean properties or constructor parameters.
@Component:
  - it is used to represent our class as spring bean and  Spring will automatically detect and register this class as a bean during component scanning
@EnableAutoConfiguartion:
  - is to enable  the auto configuration ,auto configuration whwn we load a dependecy it releated class will be loaded.
@SpringBootApplication:
  -it is equals to three annotations -@ComponenrtScan,@Configuartion and @Spring
@LookUp:
  -it sits on the  abstract method when if we call this method then Spring generates and provides a concrete implementation of that method's return type dynamically.
@RequestBody:
  -  Binds the HTTP request body to a method parameter in a controller, typically used in RESTful APIs for receiving data in JSON or XML format.
@ResponseBody:
  - Indicates that the return value of a controller method should be serialized directly to the HTTP response body, typically used in RESTful APIs for sending data in JSON or XML format
@PathVariable:
  - extracts the value from the uri and binds to the paramters in the controller method in the from of the path type for example-http://ip:p/{path}.
@RequestParam:
  - it uses to bind the data which is coming from the query string 
@RequestHeader:
  - It is used to extract the http headers in the controller method
@RestController:
  - it is combination of two @Compoent+@ResponseBody it used  for  rest api communcations
@RequestAttribute:
  - It is used to extract the http request attributes in the controller method
@CookieValue:
  -  is used to extract a specific cookie value from the HTTP request in a controller method parameter
@CrossOrigin:
 - n Spring is used to configure Cross-Origin Resource Sharing (CORS) for web services.for which request domain uri can hit the another domain.it gives access.
@ControllerAdvice:
 - It is used to handle the gloabal exceptions ,and it is a class level 
@ExceptionHandler:
 - it handles the exception with the same class by using this annoation
@EnableJpaRepositories:
 - it is used to enable datajpa repositories in springboot and it set us the infrastructure neccessary for springatajap to work with repositories.
@EnableCaching:
 -it enable caching which is present on the Configuartion class i.e main class
   - @Cachable:
        - it used to store the data in cache when a user hit url it checks the cache if same request is hit then it will send the data stored in cache it is method level
   - @CachePut:
        - it is used ot update the cache data
  -  @CacheEvict:
        - it is used to remove the entites from cache.
@Service:
 - to represent class as a service class
@Repository:
 - to represent  as repository
@Controller:
 - to represent our class as controller class
@Primary:
 -w Used in conjunction with @Autowired to give priority to a specific bean when multiple beans of the same type are available for injection.
@RequestMapping:
 - when arequest
 will hit any method in comtroller willfirst hit the request mapping path.
@PropertySource(value ="classpath:app.properties")
it will load the properties and we can have multiple propertysources
@Resource:
When Spring encounters @Resource, it tries to match a bean by name. If a bean with the exact name is not found, it then tries to match by type.
@Inject:
Spring will match a bean by type to inject when it sees @Inject. It will throw an error if no matching bean is found or if there are multiple beans with the same type unless qualifiers are used.
@ConditionalOnClass:
This annotation tells Spring to only configure a bean if a specified class is present on the classpath.
@ConditionalOnMissingBean:
This annotation tells Spring to configure a bean only if a particular bean type does not already exist in the application context.

@ConditionalOnProperty:
This annotation configures beans based on the value of a property, allowing configuration based on application properties.
@ConfigurationProperties:
This annotation is used to bind properties from external sources (such as application.properties or application.yml) to a Java class.
@Import:
his annotation allows you to import additional configuration classes or beans into the application context.
@Lazy we can use this in clas and method level so that when ioc startup it will not craete bean for this at the time of we load it willc reate
@Profile("dev") -> based on profile it will load beans

Cascade:

Types of Cascade Operations

Here are the main types of cascading:

PERSIST: When you move to a new house (save parent), you take your kids along (save children).

  • REMOVE: When you quit your job (delete parent), you cancel your kids' daycare (delete children).

  • MERGE: If you change your last name (update parent), your kids' last names also change (update children).

  • REFRESH: If you check your bank account (refresh parent), you also check your kids' savings accounts (refresh children).

  • DETACH: If you move out of a country (detach parent), your kids are no longer tracked by your hometown (detach children).

  • ALL: Apply all these rules whenever you do so