Top Spring Security Interview Questions (2020) | CodeUsingJava








Most frequently asked Spring Boot Interview Questions



What is Spring Boot?

  • Spring consists of a number of modules. Previously for each module the dependencies needed to be imported seperately. So for example Spring AOP needs multiple dependencies. All these dependencies needed to be imported individually in the pom or gradle file. With different versions of these dependencies there used to be many conflicts which needed to be resolved and could cause issues. Spring Boot is a project that is built on the top of the Spring Framework. It provides an easier and faster way to set up, configure, and run both simple and web-based applications. With Spring Boot we just need to provide the Spring AOP starter dependency. With this all the dependencies related to AOP with their correct versions are automatically downloaded by spring.


What is the use of @SpringBootApplication annotation?

@SpringBootApplication annotation was introduced in Spring Boot 1.2.0. Using this annotation enables the auto-configuration feature
This annotation enables the following 3 annotation -
  • @Configuration - Registering the beans
  • @ComponentScan - Component scanning to discover the controller and component classes automatically.
  • @EnableAutoConfiguration - Enable the Spring Boot autoconfiguration


What is Spring Actuator? How to make use of it?

Actuator is used to bring production-ready features to our application. It is responsible for monitoring app, gathering metrics, understanding traffic, or the state of the database.
It provides secured endpoints for monitoring and managing your Spring Boot application. By default, all actuator endpoints are secured.
When using Maven Framework include the following dependency
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
When using Gradle Framework include the following dependency
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'


What is Spring Security? How to enable Spring Security?

Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications.
Spring Security is a framework that focuses on providing both authentication and authorization to Java applications. Like all Spring projects, the real power of Spring Security is found in how easily it can be extended to meet custom requirements
If Spring Security is on the classpath, Spring Boot automatically secures all HTTP endpoints with "basic" authentication. However, you can further customize the security settings. The first thing you need to do is add Spring Security to the classpath. When using Maven Framework include the following dependency
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-security</artifactId>
</dependency>
When using Gradle Framework include the following dependency
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security'

How to start Spring Boot Application on a port other than the default port 8080

By default spring boot starts on port 8080. This can be changed by specifying in the application.properties the port on which spring boot should be started-
server.port = 8081
This will start spring boot on port 8081

What is Spring Boot Dev Tools? How to use it?

Spring Boot 1.3 provides another module called Spring Boot DevTools. DevTools stands for Developer Tool. The aim of the module is to try and improve the development time while working with the Spring Boot application. Spring Boot DevTools pick up the changes and restart the application.
When using Maven Framework include the following dependency
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-devtools</artifactId>
</dependency>
When using Gradle Framework include the following dependency
compile group: 'org.springframework.boot', name: 'spring-boot-starter-devtools'
 

What are the features of Spring Boot Devtools

  • Automatic Restart
  • Property Defaults
  • Live Reload
  • Remote Debug Tunneling
  • Remote Update and Restart
  • Global Configuration