InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Have You Used Activemq In Spring Boot Application? Do You Know How To Configure External Activemq? |
|
Answer» Spring Boot COMES with embedded ACTIVEMQ.We NEED to USE “spring–boot–starter–activemq” dependency in pom.xml and it will take care of all defaults and will configure ActiveMQ in the project. If you want to configure external ActiveMQ then you need to just PUT “spring.activemq.broker-url” in application.properties and provide the URL of external ActiveMQ. Spring Boot comes with embedded ActiveMQ.We need to use “spring–boot–starter–activemq” dependency in pom.xml and it will take care of all defaults and will configure ActiveMQ in the project. If you want to configure external ActiveMQ then you need to just put “spring.activemq.broker-url” in application.properties and provide the URL of external ActiveMQ. |
|
| 2. |
What Are Embedded Containers Which Are Supported By Spring Boot? |
|
Answer» Spring BOOT CONTAINS EMBEDDED TOMCAT, Jetty and UNDERTOW servers. Spring boot contains embedded Tomcat, Jetty and undertow servers. |
|
| 3. |
How Can You Implement Spring Security In Spring Boot Application? |
|
Answer» Implementation of Spring SECURITY in Spring BOOT application requires very little configuration. You need to ADD spring-boot-starter-security starter in pom.xml.You need to create Spring config class which will EXTEND WebSecurityConfigurerAdapter and override REQUIRED method to achieve security in Spring boot application. Implementation of Spring security in Spring boot application requires very little configuration. You need to add spring-boot-starter-security starter in pom.xml.You need to create Spring config class which will extend WebSecurityConfigurerAdapter and override required method to achieve security in Spring boot application. |
|
| 4. |
What Is Devtools In Spring Boot? |
|
Answer» Spring boot COMES with DEVTOOLS which is introduced to increase the PRODUCTIVITY of developer. You don’t need to deploy your application every time you make the changes.Developer can simply RELOAD the changes without restart of the server. It avoids pain of deploying application every time when you make any change. This MODULE will be disabled in production environment. Spring boot comes with DevTools which is introduced to increase the productivity of developer. You don’t need to deploy your application every time you make the changes.Developer can simply reload the changes without restart of the server. It avoids pain of deploying application every time when you make any change. This module will be disabled in production environment. |
|
| 5. |
What Is Name Of The Configuration File Which You Use In Spring Boot? |
|
Answer» CONFIGURATION file used in SPRING BOOT projects is application.properties. It is very important file as it is used to override all default configurations. Configuration file used in Spring boot projects is application.properties. It is very important file as it is used to override all default configurations. |
|
| 6. |
Can We Use Spring Boot With Applications Which Are Not Using Spring? |
|
Answer» No, it is not POSSIBLE as of now. SPRING BOOT is LIMITED to Spring APPLICATIONS only. No, it is not possible as of now. Spring boot is limited to Spring applications only. |
|
| 7. |
What Is Spring Boot Starter And How It Is Useful? |
|
Answer» SPRING boot comes with a lot of starters which is set of convenient dependency DESCRIPTORS which you can include in your pom.xml. For example: Let’s SAY you WANT to work Spring MVC application, you can simply include “spring–boot–starter–web” as dependency in pom.xml . Spring boot comes with a lot of starters which is set of convenient dependency descriptors which you can include in your pom.xml. For example: Let’s say you want to work Spring MVC application, you can simply include “spring–boot–starter–web” as dependency in pom.xml . |
|
| 8. |
How Can You Run Spring Boot Application On Custom Port? |
|
Answer» You can SIMPLY PUT server.port PROPERTIES in application.properties. For EXAMPLE:server.port=8050. You can simply put server.port properties in application.properties. For example:server.port=8050. |
|
| 9. |
How Can You Override Default Properties In Spring Boot Project? |
|
Answer» SPRING boot provides a lot of PROPERTIES which can be OVERRIDDEN by specifying them in application.properties. For example: You want to specify prefix and suffix in Spring MVC applications. You can SIMPLY do it by putting below properties in application.properties. spring.mvc.view.prefix: /WEB-INF/ spring.mvc.view.suffix: .JSP Spring boot provides a lot of properties which can be overridden by specifying them in application.properties. For example: You want to specify prefix and suffix in Spring MVC applications. You can simply do it by putting below properties in application.properties. spring.mvc.view.prefix: /WEB-INF/ spring.mvc.view.suffix: .jsp |
|
| 10. |
Why Did You Use Spring Boot In Your Application? |
|
Answer» As discussed earlier, SPRING BOOT makes it EASIER for you to create Spring application, it can save a lot of time and efforts. For EXAMPLE: Let’s say you want to create Spring boot PROJECT with activeMQ. You can simply use “spring–boot–starter–activemq” as artifact Id, it will take all the defaults and create Spring application with ActiveMQ configured. Let’s say you don’t want to use inbuilt activeMQ, you can simply override “spring.activemq.broker-url” in application.properties to use external ActiveMQ. As discussed earlier, Spring boot makes it easier for you to create Spring application, it can save a lot of time and efforts. For example: Let’s say you want to create Spring boot project with activeMQ. You can simply use “spring–boot–starter–activemq” as artifact Id, it will take all the defaults and create Spring application with ActiveMQ configured. Let’s say you don’t want to use inbuilt activeMQ, you can simply override “spring.activemq.broker-url” in application.properties to use external ActiveMQ. |
|
| 11. |
What Is Yaml? |
Answer»
|
|
| 12. |
How To Configure Datasource Using Spring Boot? |
|
Answer» Use EITHER SPRING-boot-starter-jdbc or spring-boot-starterdata-jpa and include a JDBC driver on classpath Declare properties: spring.datasource.url=jdbc:mysql://localhost/test spring.datasource.username=dbuser spring.datasource.password=dbpass spring.datasource.driver-class-name=com.mysql.jdbc.Driver
Use either spring-boot-starter-jdbc or spring-boot-starterdata-jpa and include a JDBC driver on classpath Declare properties: spring.datasource.url=jdbc:mysql://localhost/test spring.datasource.username=dbuser spring.datasource.password=dbpass spring.datasource.driver-class-name=com.mysql.jdbc.Driver |
|
| 13. |
How To Implement Spring Web Using Spring Boot? |
Answer»
|
|
| 14. |
What Is The Configuration File Name Used By Spring Boot? |
|
Answer» The configuration file used in spring BOOT projects is application.properties. This file is very important where we would over write all the DEFAULT CONFIGURATIONS. Normally we have to keep this file under the resources folder of the project. The configuration file used in spring boot projects is application.properties. This file is very important where we would over write all the default configurations. Normally we have to keep this file under the resources folder of the project. |
|
| 15. |
How To Implement Security For Spring Boot Application ? |
|
Answer» Add SPRING SECURITY starter to the boot application <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> Add spring security starter to the boot application <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> |
|
| 16. |
How To Run Spring Boot Application To Custom Port ? |
|
Answer» In application.properties, ADD FOLLOWING PROPERTY. server.port = 8181. In application.properties, add following property. server.port = 8181. |
|
| 17. |
What Is Actuator In Spring Boot? |
|
Answer» Spring Boot Actuator is a sub-project of Spring Boot. It ADDS SEVERAL production grade services to your application with little effort on your part. There are also has many features added to your application out-of-the-box for managing the service in a production (or other) environment. They’re mainly used to expose different types of information about the running application – health, METRICS, info, DUMP, ENV etc. Spring Boot Actuator is a sub-project of Spring Boot. It adds several production grade services to your application with little effort on your part. There are also has many features added to your application out-of-the-box for managing the service in a production (or other) environment. They’re mainly used to expose different types of information about the running application – health, metrics, info, dump, env etc. |
|
| 18. |
How To Reload My Changes On Spring Boot Without Having To Restart Server? |
|
Answer» Include following maven dependency in the application. <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> <version>1.2.6.RELEASE</version> </dependency> Automatic restart Applications that use spring-BOOT-devtools will automatically restart whenever files on the classpath change. This can be a USEFUL feature when working in an IDE as it GIVES a very fast feedback loop for code changes. By default, any entry on the classpath that points to a folder will be monitored for changes. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> This can be achieved USING DEV Tools. With this dependency any changes you save, the embedded tomcat will restart. Spring Boot has a Developer tools (DevTools) module which helps to improve the productivity of developers. One of the key challenge for the Java developers is to auto deploy the file changes to server and auto restart the server. Developers can reload changes on Spring Boot without having to restart my server. This will eliminates the need for manually deploying the changes every time. Spring Boot doesn’t have this feature when it has released it’s first version. This was a most requested features for the developers. The module DevTools does EXACTLY what is needed for the developers. This module will be disabled in the production environment. Include following maven dependency in the application. <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> <version>1.2.6.RELEASE</version> </dependency> Automatic restart Applications that use spring-boot-devtools will automatically restart whenever files on the classpath change. This can be a useful feature when working in an IDE as it gives a very fast feedback loop for code changes. By default, any entry on the classpath that points to a folder will be monitored for changes. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> This can be achieved using DEV Tools. With this dependency any changes you save, the embedded tomcat will restart. Spring Boot has a Developer tools (DevTools) module which helps to improve the productivity of developers. One of the key challenge for the Java developers is to auto deploy the file changes to server and auto restart the server. Developers can reload changes on Spring Boot without having to restart my server. This will eliminates the need for manually deploying the changes every time. Spring Boot doesn’t have this feature when it has released it’s first version. This was a most requested features for the developers. The module DevTools does exactly what is needed for the developers. This module will be disabled in the production environment. |
|
| 19. |
Can You Control Logging With Spring Boot? How? |
|
Answer» Yes, we can CONTROL LOGGING with spring boot. Customizing default CONFIGURATION for Logging: By ADDING logback.xml file to the application we can override the default logging configuration providing by the Spring Boot. This file place in the classpath (src/main/resources) of the application for Spring Boot to pick the custom configuration. Spring Boot can control the logging level Just set it in application.properties Works with most logging frameworks Java Util Logging, Logback, Log4J, Log4J2 logging.level.org.springframework=DEBUG logging.level.com.acme.your.code=INFO Yes, we can control logging with spring boot. Customizing default Configuration for Logging: By adding logback.xml file to the application we can override the default logging configuration providing by the Spring Boot. This file place in the classpath (src/main/resources) of the application for Spring Boot to pick the custom configuration. Spring Boot can control the logging level Just set it in application.properties Works with most logging frameworks Java Util Logging, Logback, Log4J, Log4J2 logging.level.org.springframework=DEBUG logging.level.com.acme.your.code=INFO |
|
| 20. |
What Is A Spring Boot Starter Pom? Why Is It Useful? |
|
Answer» Starters are a set of convenient dependency descriptors that you can include in your APPLICATION. The starters contain a lot of the dependencies that you NEED to get a project up and running quickly and with a consistent, supported set of managed transitive dependencies. The starter POMs are convenient dependency descriptors that can be added to your application’s MAVEN. In simple words, if you are developing a project that USES Spring Batch for batch processing, you just have to include spring-boot-starter-batch that will import all the required dependencies for the Spring Batch application. This reduces the BURDEN of searching and configuring all the dependencies required for a framework. Starters are a set of convenient dependency descriptors that you can include in your application. The starters contain a lot of the dependencies that you need to get a project up and running quickly and with a consistent, supported set of managed transitive dependencies. The starter POMs are convenient dependency descriptors that can be added to your application’s Maven. In simple words, if you are developing a project that uses Spring Batch for batch processing, you just have to include spring-boot-starter-batch that will import all the required dependencies for the Spring Batch application. This reduces the burden of searching and configuring all the dependencies required for a framework. |
|
| 21. |
What Embedded Containers Does Spring Boot Support? |
|
Answer» Spring Boot includes support for embedded TOMCAT, Jetty, and Undertow SERVERS. By DEFAULT the embedded SERVER will listen for HTTP requests on PORT 8080. Spring Boot includes support for embedded Tomcat, Jetty, and Undertow servers. By default the embedded server will listen for HTTP requests on port 8080. |
|
| 22. |
What Is The Difference Between An Embedded Container And A War? |
|
Answer» There is no force to GO container LESS
There is no force to go container less |
|
| 23. |
How Are Properties Defined? Where? |
|
Answer» In SPRING boot, we have to define properties in the APPLICATION.properties file exists in classpath of application as FOLLOW. Example: configure default DATASOURCE bean. database.host=localhost database.user=admin In spring boot, we have to define properties in the application.properties file exists in classpath of application as follow. Example: configure default DataSource bean. database.host=localhost database.user=admin |
|
| 24. |
How Does It Work? How Does It Know What To Configure? |
Answer»
|
|
| 25. |
Why Is It “opinionated”? |
|
Answer» It follows “Opinionated Defaults Configuration” Approach to reduce Developer effort. Due to opinionated VIEW of spring boot, what is required to get started but also we can get out if not suitable for application. Spring Boot uses SENSIBLE defaults, “opinions”, mostly based on the CLASSPATH CONTENTS. For example
It follows “Opinionated Defaults Configuration” Approach to reduce Developer effort. Due to opinionated view of spring boot, what is required to get started but also we can get out if not suitable for application. Spring Boot uses sensible defaults, “opinions”, mostly based on the classpath contents. For example |
|
| 26. |
What Are The Disadvantages Of Using Spring Boot? |
|
Answer» It is very tough and time consuming process to convert EXISTING or LEGACY SPRING Framework projects into Spring Boot Applications. It is applicable only for BRAND new/Greenfield Spring Projects. It is very tough and time consuming process to convert existing or legacy Spring Framework projects into Spring Boot Applications. It is applicable only for brand new/Greenfield Spring Projects. |
|
| 27. |
What Are The Advantages Of Using Spring Boot? |
Answer»
|
|
| 28. |
What Is Spring Boot? |
|
Answer» First of all Spring Boot is not a framework, it is a WAY to ease to create stand-alone application with minimal or zero configurations. It is approach to develop spring based application with very less configuration. It provides defaults for code and annotation configuration to quick start new spring projects within no time. It leverages existing spring projects as well as Third party projects to develop production ready applications. It provides a set of Starter Pom’s or gradle BUILD files which one can use to add required dependencies and also facilitate auto configuration. Spring Boot automatically configures required classes depending on the libraries on its CLASSPATH. SUPPOSE your application want to INTERACT with DB, if there are Spring Data libraries on class path then it automatically sets up connection to DB along with the Data Source class. First of all Spring Boot is not a framework, it is a way to ease to create stand-alone application with minimal or zero configurations. It is approach to develop spring based application with very less configuration. It provides defaults for code and annotation configuration to quick start new spring projects within no time. It leverages existing spring projects as well as Third party projects to develop production ready applications. It provides a set of Starter Pom’s or gradle build files which one can use to add required dependencies and also facilitate auto configuration. Spring Boot automatically configures required classes depending on the libraries on its classpath. Suppose your application want to interact with DB, if there are Spring Data libraries on class path then it automatically sets up connection to DB along with the Data Source class. |
|