Spring related Flashcards

1
Q

Difference between @NotNull annotation and the @Column(nullable = false)

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to make spring singlton pattern thread-safe?

A

We can use prototype pattern.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the @Constraint annotation in spring?

A

@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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is @retention in spring boot and java? What are its types?

A
@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.)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why use .yml file over .properties file in spring boot config

A

.properties file has repetition of expressions like spring.application then spring.datasource but yml has structural way of dealing with this. DRY principle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is spring profile

A

Spring Profiles helps segregating your application configurations, and make them available only in certain environments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between SOA and Microservice

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Bounded context

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between @EnableAUtoCofniguration vs @ComponentScan

A

@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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are beans in Spring

A

the objects that form the backbone of your application and that are managed by the Spring IoC container are called beans.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is DI in spring.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the two main interfaces in spring IoC

A

BeanFactory and ApplicationContext

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does @configuration mean in spring

A

It means the class with that annotation contains @Bean annotation. Spring Configuration annotation indicates that the class has @Bean definition methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Most common implementations of ApplicationContext

A

FileSystemXmlApplicationContext
ClassPathXmlApplicationContext
WebXmlApplicationContext

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Types of configurations in java

A

XML based
Java-based
Annotation based

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Declarative Programming, is it implemeted in Spring boot?

A

Declarative programming is when you write your code in such a way that it describes what you want to do, and not how you want to do it. Spring Boot has declarative programming. @Transactional for example tells it what to do than how to do it.

17
Q

When are changes Flushed in spring boot?

A
  1. When an explicit session.flush() call is made
  2. When a transaction is committed
  3. Inside a transaction, before a query to the database is executed
18
Q

@PostConstruct and @PreDestroy difference

A

The @PostConstruct annotation is used to define a method that should be called after an object is created, while @PreDestroy is used to define a method that should be called before an object is destroyed

19
Q

When using data.sql file to write queries manuelly inside resources file. A probelm may arise with quering sql before the table is created by Hibernate. How to solve this?

A

spring.jpa.defer-datasource-initialization=true