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:
- https://docs.spring.io/spring-framework/docs/current/reference/html/core.html
- https://www.youtube.com/watch?v=GB8k2-Egfv0&list=PLC97BDEFDCDD169D7&index=2
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
-
constructor
-
property or class member
-
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.
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.
@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-batch processing
Spring boot interview question:
Spring Application event and Externalising event to db or message broker using spring modulith
- https://www.youtube.com/watch?v=5YdjBWSGtbE&list=RDCMUC7yfnfvEUlXUIfm8rGLwZdA&index=4
- https://docs.spring.io/spring-modulith/reference/1.1/events.html
Spring boot rest, JPA
Too long list of @RequestParams bind to object http://dolszewski.com/spring/how-to-bind-requestparam-to-object/#google_vignette
JPA locks https://www.baeldung.com/java-jpa-transaction-locks
Spring Transaction and events
https://medium.com/thefreshwrites/best-practices-for-using-transactional-in-spring-boot-7baafba397ad
Reactive Programming
https://www.youtube.com/watch?v=EExlnnq5Grs&list=PLqq-6Pq4lTTYPR2oH7kgElMYZhJd4vOGI&index=1
Spring flux
- https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux
- https://www.reactive-streams.org/
- https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.html