1.
What is a Container in docker
It is the running version of the image. We can say that image is analogous to class and container
is analogous to object .
Command to run a docker container
docker run –d –p 8080:8080 in28min/todo-rest-api-h2:1.0.0.RELEASE
{Host Port}: {Container port}
2. What is docker registry and repository
The Url : hub.docker.com is the default registry and then comes the image name that is the
repository A registry contains lot of different versions of different applications .
in28min/todo-rest-api-h2 is the repository which contains all the versions.Here 1.0.0 is the
version we want to use.
To login use the command : docker login
3. Command to open up the port for outside world to access
4. To run the container in detached mode i.e in the background
Use command –d
5. Run a docker container with specified memory and cpu
6. To execute some commands inside a docker container
docker container exec {container_id} ls /tmp
7. For logs
docker logs -f {id of the container} → This will start tailing the logs
8. List of containers which are running
docker container ls
9. List of all the containers irrespective of their status
docker container ls –a
10. Running the docker image and pausing and unpausing it
11. Docker container inspect
It gives the meta data about container
12. Docker container prune
This will remove all the stopped container
13. Docker container kill command will immediately kill the container and –restart=always , will
restart the container when docker is restarted automatically
14. Docker stats
15. To stop the container
docker container stop {container_id}
16. List of all the images
docker images
17. How to rename an image tag in docker
docker tag in28min/todo-rest-api-h2:1.0.0.RELEASE in28min/todo-rest-api-h2:latest
18. Checking the history of docker image
docker image history {id of the container}
docker inspect {id of the container} → it gives all the info about that container also what all are
the env variables
19. Removing image from local env
Docker image remove {image_id}
20. Steps for building a jar manually
Create a container as base in our case it will be openjdk
Go inside the container /tmp folder
Copy the jar from /target/*.jar to /tmp folder insde the docker
Create a new image of this container which has the jars
For running on windows
Else we can use normal command
21. Creating image using a Dockerfile
22. Creating a docker image using buildpacks
In pom.xml where plugins are defined do the below changes
Run the command “mvn:spring-boot:build-image”
23. Creating docker image using google Jib
In pom.xml add the google jib plugin
Run the command mvn compile jib:dockerBuild
========================================================================
========================================================================
SPRING SECURITY
24. List of filters in spring security
25. How to add spring security to your spring boot application
Using spring-boot-starter- security as dependency in pom.xml
26. When we add spring security in pom.xml then all our application is secured , what is the
default username and password
Default username is user and password we get from console
27. How to override default username and password
spring.security.user.name= sujeet
spring.security.user.password=Sujeet
28. Spring security internal flow diagram
29. Importance of authorization filter and how the flow of spring security works
1. Authorization filter : It will restrict the access of url that the user is trying to access.If its public
url then response will be provided back without asking any credentials
Here the do filter method will take the help of authorization manager to check if its a public or
private url , if its private then it will hand over the request to next filter.
2. DefaultLoginPageGeneratingFilter 👍
Login page is generated using this filter .
3. UsenamePasswordAuthenticationFilter : Once the user enters username and password then
the next filter that comes into place is usernamePasswordAuthenticationFilter . Inside this there
is a method called attemptauthentication , its responsibility is to extract username and
password from the request
.With this it forms an object of usernamePasswordAuthenticationToken . It extends
authentication interface .The same object it is going to handover to authentication manager by
invoking the authenticate method.AuthenticationManager is an interface . In spring the
implementation of this authentication manager is ProviderManager .
This providerManager will interact with all the authentication providers until it sees successful
authentication or a failure authentication , by default it is daoAuthentication provider which
extends AbstractUserDetailsAuthenticationProvider . Here first of all it will retrieve username
from USerDetailsService
by default userdetailsService is implemented by InMemoryUserDetailsManager which loads
user details from in memory
30. Which filter is responsible for generating a default login page for entering username and
password .
DefaultLoginPagegeneratingFilter
31. Which filter class creates an object of authentication
UsernamePasswordAuthenticationFilter#AttemptAuthentication creates an object of
UsenamePasswordAuthenticationToken which implements authentication interface from
HttpServletRequest .Once this object is created it is going to invoke authenticate method inside
the authenticate manager object .
32. Implementation class for authentication manager
AuthenticationManager is an interface and spring provided its implementation in class
ProviderManager . Inside this class there is a method called authenticate which has a for loop
for providers . This ProviderManager class will loop through all the provider and will try to
invoke the authenticate method in each provider . By default the spring has a default
authentication provider called DaoAuthenticationProvider
33. By default which UserDetailsManager spring uses
Spring uses by default InMemoryUserDetailsManager
34. Where the default configuration is done inside the spring security framework for securing
URLS
35. Configuring multiple user in inmemory
36. Custom security configuration
37. Implementaion of UserDetailsService
38. Authenticating using JdbcuserDetailsManager
First we need to create a bean of the type JdbcUserDetailsManager which takes a
datasource as an input parameter.
Internally it will call loadUserByUserName(String username)
We also need to have a table in db with the following details
39. Custom authenticating user with email
Create an entity named customer
Create a repository
Override user details service class
40. Authenticating using a password encoder
41. What is CORS and how to enable it
42. What is CSRF and how to fix it
43. Handling Authorities and Roles
44. What is JWT token and how to implement it
Make changes in pom.xml file
=====================================================================================
=====================================================================================
SPRING AOP
45. What is AOP
46. Example of an AOP
47. Types of AOP
48. How to configure a custom advice using annotation
==============================================================================
===========================================================================
SPRING MVC
49. What is spring core and what all are its important features
50. What is a dependency injection
ComplexAlgorithmImpl binarySearch =
New ComplexAlgorithmImpl(new QuickSortAlgorithm());
This functionality is implemented by spring for us . Whenever it sees @autowire then it looks for
a bean of that type and injects it by setter injection or constructor injection.
Spring searches for the bean , finds the appropriate bean and autowire it in here.
Dependency injection is the process in which spring looks for the bean , identifies the
dependency and creates the instances of the bean and autowires them in .
ComplexAlgorithmImpl binarySearch =
New ComplexAlgorithmImpl(new QuickSortAlgorithm());
This kind of stuff is done by spring.
51. What is IOC
The right to create an object is moved from programmer to framework.
52. What is spring bean, context and spEl
53. What is IocContainer
54. What is bean factory and application context.
Bean factory does what basic of any IOC container does like
Find the beans
Wire the dependencies
Manage Lifecycle of the beans
Application Context : Another form of application context but with enhanced features
Bean Factory ++
Spring AOP features : Provides spring aspect oriented programming
I18n capabilities – internationalization capabilities , things like message sources
Web Application Context for web applications – like request , session , request scope ,
session scope
Spring recommends you to use application context. Use bean factory when u are in need of
severe memory constraint.
55. Different ways of creating an application context.
56. What is @autowired
57. Different ways of autowiring
58. How autowiring works with multiple beans of same type @Qualifier annotation
59. @Bean annotation and give a custom name to your bean
60. @configuration annotation
It is an annotation inside spring which will let your framework know that this class has certain
configuration like bean definition . So we tell spring IOC container to process this class while
starting the container.
61. @primary
62. NoUniqueBeandefinationException
63. @componentscan
It is bascally a search spring does for the components. Input for the search is the packages.
64. @component annotation
65. What is the difference between @Component, @controller, @repository @service
66. Difference between bean and component
67. Bean scopes
68. What is singleton bean scope
69. Prototype bean scope
70. Difference between singleton and prototype bean scope
71. Lazy and eager initialization
72. Difference between setter and constructor injection
73. How does spring does autowiring
By default spring uses byType
74. @predestroy and @postsonstruct
75. How to register a bean programmatically
76. Design patterns used in spring
77. @RequestMapping
78. Viewresolver in spring
79. What is a model in spring
Model can only store data
80. What is a dispatcher servlet and how would you setup a dispatcher servlet
Every request would first come to a dispatcher servlet and dispatcher servlet would then
forward it to the correct controller. From the controller we would get a view name and
dispatcher servlet will map it to the correct view using view resolver.
81. @ResponseBody
82. @RestController
83. What is path variable
84. @RequestParam
85. @RequestBody
86. What is ResponseEntity
87. How to create a custom exception handling in springboot application
88. Input validation exception
=====================================================================================
====================================================================================
LOMBOK
89. Different annotations used in Lombok
==============================================================================
===========================================================================
SPRING JDBC
90. What is a JDBC template
91. Select query using jdbc template
92. Insert/Update/Delete using jdbc template
93. Create sql commands using jdbc template
94. Rowmapper example using jdbc template
95. NamedParameter Jdbc template
======================================================================
H2 database
96. What is an h2 database
97. To enable h2 database we need to do the following configurations
Open the url : http://localhost:8080/h2-console
Create a file schema.sql and this will contain DDL statements
Entity
==============================================================================
==============================================================================
SPRING DATA JPA
98. How to enable spring-data-jpa
99. How to enable auditing in spring application for fields createdBy and ModifiedBy
SPRINGBOOT
100. @SpringBootApplication
101. What is autoconfiguration
102. Server.port
It is used to define a custom port to our spring application
Server.port
103. @JsonProperty
104. What is the order of configuration properties set up
105. Different ways of reading properties in spring boot application
106. @value annotation
107. How can we override properties file values using command line
108. Reading property files using env variable
109. How can we pass env variables manually
Syntax is say you want to override build.version then use “BUILD_VERSION” all in caps and
remove . with _.
110. @configurationProperties
In main class which has main method
111. What is profile
=================================================================
==============================================================
SWAGGER
112. How to add swagger dependency
113. Url to access swagger
http://localhost:8080/swagger-ui/index.html
114. @openApiDefination annotation
115. @tag annotation
116. @operation annotation
117. @ApiResponse annotation
118. @Schema annotation
============================================================================
SPRING CLOUD CONFIG
119. Create a spring cloud config server project.
120. Structure of spring cloud config project
121. How to integrate spring cloud config server with git
Structure of git
122. Connect config client to config sever
123. How to refresh properties without restarting the server
We need to have a dependency spring-boot-starter-actuator in pom.xml
We then need to enable actuator endpoints
In application.yaml file
Use the refresh api
124. How we can configure the refresh api of spring boot actuator
=========================================================================
========================================================
JUNIT
125. What is unit testing
126. What is integration testing
127. What is Junit and Mockito
128. Maven dependency for Junit
129. Unit test structure
130. Simple junit test example
131. Junit Assert
Assert true and false
132. Assertion for throws and timeout
133. Junit lifecycle methods @beforeEach and @AfterEach
134. @BeforeAll and @AfterAll annotation
135. Display Name
136. @order annotation
137. Configure Maven to find unit test
138. Generate unit test report
139. Generate code coverage report using Jacoco
140. @SpringBootTest
141. What if test class is in a different package
142. Use mockito configuration
143. Mockito using @mockbean annotation
144. Handle exception using mockito
145. Spy annotation
When we use @mock then entire behavior of the interface or class gets lost. In spy the behavior
of the class is retained and what all thing we ovevride will be ovveriden.
146. @WebMvcTest
Using this annotation we can say to spring that the input to
@WebMvcTest(HelloWorldController.class) is the controller we want to unit test.
147. Simple unit test to check the controller returning “hello”
148. To check json response
149. Junit for post method
150. Junit for pathvariable
151. Writing junit for service layer
152. Reading properties file from application-test.yaml file