Spring related Flashcards
Difference between @NotNull annotation and the @Column(nullable = false)
In @NotNull Hibernate didn’t trigger the SQL insert statement. pre-persist entity lifecycle event triggered the bean validation just before sending the query to the database. (DB call not made)
@Column(nullable = false) throws SqlException. Hibernate sends any insert or update SQL queries to the database. And the DB throws an error. (DB call made)
How to make spring singlton pattern thread-safe?
We can use prototype pattern.
What is the @Constraint annotation in spring?
@Constraint marks an annotation as being a Bean Validation constraint and allows us to specify ConstraintValidator implementations; zero, one, or many implementations are welcome here
What is @retention in spring boot and java? What are its types?
@Retention : Specifies whether the annotation metadata can be accessed at runtime by the application. Types, RetentionPolicy.RUNTIME (Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.), RetentionPolicy.SOURCE (Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.), RetentionPolicy.CLASS(Annotations are to be discarded by the compiler.)
Why use .yml file over .properties file in spring boot config
.properties file has repetition of expressions like spring.application then spring.datasource but yml has structural way of dealing with this. DRY principle
what is spring profile
Spring Profiles helps segregating your application configurations, and make them available only in certain environments
What is the difference between SOA and Microservice
The main distinction between the two approaches comes down to scope. service-oriented architecture (SOA) has an enterprise scope, while the microservices architecture has an application scope.
SOA needs ESB to communicate and ESB was smart (decides business logic)
Microservice use MEssaging brokers (Messaging brokers are dumb and endpoints are smart)
SOA is centralized
Microservice are decentralized
What is Bounded context
Bounded context defines tangible boundaries of applicability of some sub-domain. It is an area where a certain sub-domain makes sense, while the others don’t.
What is the difference between @EnableAUtoCofniguration vs @ComponentScan
@ComponentScan scans for Spring components (@Bean, @Component, @Controller, @Service, and @Repository.)
@EnableAutoConfiguration annotation enables Spring Boot to auto-configure the application context. Therefore, it automatically creates and registers beans based on both the included jar files in the classpath and the beans defined by us.
What are beans in Spring
the objects that form the backbone of your application and that are managed by the Spring IoC container are called beans.
What is DI in spring.
Spring provided loose coupling is application by Dependency Injection.
It uses Inversion of Control
technique by which objects specify their dependencies to Spring
container instead of creating new objects themselves.
What are the two main interfaces in spring IoC
BeanFactory and ApplicationContext
What does @configuration mean in spring
It means the class with that annotation contains @Bean annotation. Spring Configuration annotation indicates that the class has @Bean definition methods.
Most common implementations of ApplicationContext
FileSystemXmlApplicationContext
ClassPathXmlApplicationContext
WebXmlApplicationContext
Types of configurations in java
XML based
Java-based
Annotation based