Web || Spring || Springboot || Reactive - ashish-ghub/docs GitHub Wiki

Web:

Session and JWT:

https://ponyfoo.com/articles/json-web-tokens-vs-session-cookies


Spring core

Spring Core docs:

Spring Boot docs:

https://docs.spring.io/spring-boot/docs/2.7.3/reference/htmlsingle/#getting-started

Spring Basics


difference between @Inject and @Autowired in Spring

Assuming here you're referring to the javax.inject.Inject annotation. @Inject is part of the Java CDI (Contexts and Dependency Injection) standard introduced in Java EE 6 (JSR-299), read more. Spring has chosen to support using the @Inject annotation synonymously with their own @Autowired annotation.

So, to answer your question, @Autowired is Spring's own annotation. @Inject is part of a Java technology called CDI that defines a standard for dependency injection similar to Spring. In a Spring application, the two annotations works the same way as Spring has decided to support some JSR-299 annotations in addition to their own.

Spring injection

3 types of injection supported

  1. constructor

  2. property or class member

  3. setter of property

Automated Java-Based Configuration

To support automated Java-based configuration, Spring provides additional annotations. While there are numerous, rich annotations that we can use, there are three foundational annotations:

@Component: Registers as a class as being managed by Spring.

@Autowired: Instructs Spring that a dependency should be injected.

@ComponentScan: Instructs Spring where to look for classes annotated with @Component

What are Stereotype annotations?

The Spring Framework provides you with some special annotations. These annotations are used to create Spring beans automatically in the application context. The main stereotype annotation is @Component. By using this annotation, Spring provides more Stereotype meta annotations such as @Service, used to create Spring beans at the Service layer, @Repository, which is used to create Spring beans for the repositories at the DAO layer, and @Controller, which is used to create Spring beans at the controller layer. This is depicted in the following diagram:

define @Bean :

ThreadPoolTaskExecutor is a java bean that allows for configuring a ThreadPoolExecutor in a bean style as below

 @Bean
 public TaskExecutor threadPoolTaskExecutor() {
   ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
   executor.setCorePoolSize(5);
   executor.setMaxPoolSize(10);
   executor.initialize();
   return executor;

}

All Annotation is spring:

https://dzone.com/articles/a-guide-to-spring-framework-annotations

bean-lifecycle https://reflectoring.io/spring-bean-lifecycle/

Spring Circular dependencies https://www.baeldung.com/circular-dependencies-in-spring

Resolved using Use Setter/Field Injection

@Component

public class CircularDependencyA {

private CircularDependencyB circB;

@Autowired
public void setCircB(CircularDependencyB circB) {
    this.circB = circB;
}

public CircularDependencyB getCircB() {
    return circB;
}

}

@Component

public class CircularDependencyB {

private CircularDependencyA circA;

private String message = "Hi!";

@Autowired
public void setCircA(CircularDependencyA circA) {
    this.circA = circA;
}

public String getMessage() {
    return message;
}

}

-> How to create Factory for payment service to choose right service based on user selection parameter

@Service public class LazyPaymentServiceFactory implements PaymentServiceFactory {

@Autowired
@Lazy
private PayPalPaymentService payPalPaymentService;

@Autowired
@Lazy
private StripePaymentService stripePaymentService;

@Override
public PaymentService createPaymentService(String paymentServiceName) {
    if ("paypal".equals(paymentServiceName)) {
        return payPalPaymentService;
    } else if ("stripe".equals(paymentServiceName)) {
        return stripePaymentService;
    }
    // Handle other payment services as needed
    throw new IllegalArgumentException("Unsupported payment service: " + paymentServiceName);
}

}

Spring boot design pattern.

https://jackynote.medium.com/top-5-design-patterns-in-java-spring-boot-best-practices-and-examples-002c45d3d331


Spring Session: (cloud or distributed way of session management)

Spring Session has the simple goal of free up session management from the limitations of the HTTP session stored in the server.

The solution makes it easy to share session data between services in the cloud without being tied to a single container (i.e. Tomcat). Additionally, it supports multiple sessions in the same browser and sending sessions in a header.

  1. https://www.baeldung.com/spring-session

  2. https://spring.io/projects/spring-session

@ConfigurationProperties vs. @Value

The @Value annotation is a core container feature, and it does not provide the same features as type-safe configuration properties. The following table summarizes the features that are supported by @ConfigurationProperties and @Value:

Spring-boot-memory-performance

https://spring.io/blog/2015/12/10/spring-boot-memory-performance


Spring boot interview question:

https://www.mygreatlearning.com/blog/spring-boot-interview-questions/


Spring boot rest, JPA

Too long list of @RequestParams bind to object http://dolszewski.com/spring/how-to-bind-requestparam-to-object/#google_vignette


Reactive Programming

https://www.youtube.com/watch?v=EExlnnq5Grs&list=PLqq-6Pq4lTTYPR2oH7kgElMYZhJd4vOGI&index=1

Spring flux

Spring elastic integration:

https://reflectoring.io/spring-boot-elasticsearch/