Question 1. What Is Spring Boot?
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.
Question 2. What Are The Advantages Of Using Spring Boot?
- It is very easy to develop Spring Based applications with Java or Groovy.
- It reduces lots of development time and increases productivity.
- It avoids writing lots of boilerplate Code, Annotations and XML Configuration.
- It is very easy to integrate Spring Boot Application with its Spring Ecosystem like Spring JDBC, Spring ORM, Spring Data, Spring Security etc.
- It follows “Opinionated Defaults Configuration” Approach to reduce Developer effort
- It provides Embedded HTTP servers like Tomcat, Jetty etc. to develop and test our web applications very easily.
- It provides CLI (Command Line Interface) tool to develop and test Spring Boot (Java or Groovy) Applications from command prompt very easily and quickly.
- It provides lots of plugins to develop and test Spring Boot Applications very easily using Build Tools like Maven and Gradle
- It provides lots of plugins to work with embedded and in-memory Databases very easily.
Question 3. What Are The Disadvantages Of Using Spring Boot?
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.
Question 4. Why Is It “opinionated”?
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.
- Sets up a JPA Entity Manager Factory if a JPA implementation is on the classpath.
- Creates a default Spring MVC setup, if Spring MVC is on the classpath.
- Everything can be overridden easily
- But most of the time not needed.
Question 5. How Does It Work? How Does It Know What To Configure?
- Auto-configuration works by analyzing the classpath
- If you forget a dependency, Spring Boot can’t configure it
- A dependency management tool is recommended
- Spring Boot parent and starters make it much easier
- Spring Boot works with Maven, Gradle, Ant/Ivy
- Our content here will show Maven.
Question 6. How Are Properties Defined? Where?
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.
Question 7. What Is The Difference Between An Embedded Container And A War?
There is no force to go container less
- Embedded container is just one feature of Spring Boot
- Traditional WAR also benefits a lot from Spring Boot
- Automatic Spring MVC setup, including DispatcherServlet
- Sensible defaults based on the classpath content
- Embedded container can be used during development.
Question 8. What Embedded Containers Does Spring Boot Support?
Spring Boot includes support for embedded Tomcat, Jetty, and Undertow servers. By default the embedded server will listen for HTTP requests on port 8080.
Question 9. What Is A Spring Boot Starter Pom? Why Is It Useful?
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.
Question 10. Can You Control Logging With Spring Boot? How?
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
Question 11. How To Reload My Changes On Spring Boot Without Having To Restart Server?
Include following maven dependency in the application.
org.springframework springloaded 1.2.6.RELEASE
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.
org.springframework.boot spring-boot-devtools true
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.
Question 12. What Is Actuator In Spring Boot?
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.
Question 13. How To Run Spring Boot Application To Custom Port ?
In application.properties, add following property.
server.port = 8181.
Question 14. How To Implement Security For Spring Boot Application ?
Add spring security starter to the boot application
Question 15. What Is The Configuration File Name Used By Spring Boot?
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.
Question 16. How To Implement Spring Web Using Spring Boot?
- Web Application Convenience
- Boot automatically configures
- A DispatcherServlet & ContextLoaderListener
- Spring MVC using same defaults as @EnableWebMvc
- Plus many useful extra features:
- Static resources served from classpath
- /static, /public, /resources or /META-INF/resources
- Templates served from /templates
- If Velocity, Freemarker, Thymeleaf, or Groovy on classpath
- Provides default /error mapping
- Easily overridden
- Default MessageSource for I18N
Question 17. How To Configure Datasource Using Spring Boot?
Use either spring-boot-starter-jdbc or spring-boot-starterdata-jpa and include a JDBC driver on classpath
- Spring Boot will create a DataSource with properties set
- Will even use a connection pool if the library is found on the classpath.
Question 18. What Is Yaml?
- Yaml Ain’t a Markup Language
- Recursive acronym
- Created in 2001
- Alternative to .properties files
- Allows hierarchical configuration
- Java parser for YAML is called SnakeYAML
- Must be in the classpath
- Provided by spring-boot-starters.
Question 19. Why Did You Use Spring Boot In Your Application?
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.
Question 20. How Can You Override Default Properties In Spring Boot Project?
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.
Question 21. How Can You Run Spring Boot Application On Custom Port?
You can simply put server.port properties in application.properties.
Question 22. What Is Spring Boot Starter And How It Is Useful?
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 .
Question 23. Can We Use Spring Boot With Applications Which Are Not Using Spring?
No, it is not possible as of now. Spring boot is limited to Spring applications only.
Question 24. What Is Name Of The Configuration File Which You Use In Spring Boot?
Configuration file used in Spring boot projects is application.properties. It is very important file as it is used to override all default configurations.
Question 25. What Is Devtools In Spring Boot?
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.
Question 26. How Can You Implement Spring 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.
Question 27. What Are Embedded Containers Which Are Supported By Spring Boot?
Spring boot contains embedded Tomcat, Jetty and undertow servers.
Question 28. Have You Used Activemq In Spring Boot Application? Do You Know How To Configure 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.
Adv Java Interview Questions
Adv Java Tutorial
J2EE Interview Questions
Core Java Interview Questions
Hibernate Interview Questions
Core Java Tutorial
MVC Framework Interview Questions
Adv Java Interview Questions
Framework7 Interview Questions
MVC Framework Tutorial
Maven Interview Questions
J2EE Interview Questions
JUnit Interview Questions
Log4j Interview Questions
Core Java Interview Questions
Spring MVC Framework Interview Questions
Hibernate Interview Questions