What does it mean by auto configuration by spring boot ?
Spring boot automatically configure bean if its corresponding library in classpath, for example if JdbcTemplate is in classpath then spring boot will configure JdbcTemplate and will create a bean that can be injected directly where its required.
What is starter dependency in spring boot ?
Starter dependency is aggregation of common dependency that are available during build for example if we are creating a web project that exposes REST API then we require spring web , spring mvc, tomcat, jackson etc.but spring boot provides web starter that has all in single dependency.If we add all dependency individually then we need to maintain all compatible version of library but using spring boot starter we get complete package that maintains all compatible version.
What is the benefit of spring boot Command line interface (CLI) ?
When we write code in spring boot CLI and use any Object or type then spring boot CLI detects starter for that type and put all related library on classpath. After library is added on classpath it uses auto configuration to create bean or injection.
What is spring boot Actuator ?
Actuator checks the internal working of application for example if our application is working with other application it can check is other application working,what are beans in spring context,what is environment variable set by application etc.
Is spring boot application server ?
No, it uses embedded container like tomcat but itself spring boot is not application server.
What is spring Initializer ?
It is an web application that creates spring boot project for developer.we can access Initializer by
SPRING INITIALIZERHow to set up basic spring initializer project ?
Spring boot project can be set up by following steps given in link.
Spring Boot Project set upHow to create REST API using spring boot ?
Spring boot REST API project can be created by following steps given in link.
Spring Boot REST ExampleWhat is the spring Boot plugin in maven ?
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
What is the spring Boot plug in gradle ?
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:")}
what are the ways to set properties for spring boot application ?
- Command-line arguments
- JNDI attributes from java:comp/env
- JVM system properties
- Operating system environment variables
- Randomly generated values for properties prefixed with random.*
- application.properties or application.yml file referred externally
- application.properties or application.yml file referred internally
- Property sources specified by @PropertySource
- Default
Note: this list is order of precedence It means any property set higher in in list will override property set lower in in list
Which has higher precedence between application.properties and application.yml ?
application.yml
How can we make template non cachable ?
Set a property in properties file
- spring.thymeleaf.cache=false (thymeleaf)
- spring.freemarker.cache=false (Freemarker)
- spring.groovy.template.cache=false (Groovy templates)
- spring.velocity.cache=false (Velocity)
How can i change port number of embedded server ?
By default tomcat starts on 8080 port.To change it other port,we need to provide a property in .properties file.
server.port = 9000
What is the default logging in spring boot?
Logback is default to log on console at INFO level.
How can we use another logging implementation instead of Logback in spring boot ?
We need to exclude Logback from dependency for example.
For maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
For gradle
configurations { all*.exclude group:'org.springframework.boot',module:'spring-boot-starter-logging'}
Add your logging implementation, for example log4j2.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
How to test REST API in spring boot using mock MVC standaloneSetup method ?
Spring boot REST API can be tested using mock MVC standaloneSetup method following steps
given in link.
Spring Boot REST API Test with Mock MVC Using standaloneSetupHow to test REST API in spring boot using mock MVC webAppContextSetup method ?
Spring boot REST API can be tested using mock MVC webAppContextSetup method following steps
given in link.
Spring Boot REST API Test with Mock MVC Using webAppContextSetupWhat is the significance of SpringJUnit4ClassRunner ?
It helps to load spring application context in Junit based application and enables autowiring
of beans in test class.
How @SpringApplicationConfiguration is different from @Context- Configuration ?
@SpringApplicationConfiguration loads the spring application by SpringApplication,due to which it can loads external properties, spring boot logging
What is the significance of @WebIntegrationTest ?
This annotation is used on test class to test web application.For example if we have any web application that accepts request, so to test API we create actual environment ,in which application is started in embedded server and actual HTTP request is sent to test API.
How to make actuator enable for spring boot ?
To make actuator eable for spring boot we need to include only following dependency
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
Adding this dependency due to auto configuration ,actuator will enable.
Even after adding actuator on classpath why can we not access many endpoint in spring boot for example /bean, /metrics ?
Most endpoints are sensitive.It means they are not fully public.While some are for example /health and /info.
Most of the details exposed by endpoint is sensitive so only authorized user can access it, so we need to include spring security on class path
Add following dependency
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>How can we customize an endpoint in spring boot ?
We can customize endpoint as well.Each endpoint has three properties.
- id: id of the endpoint
- enabled: false means it can not be accessed
- sensitive: false means no authorize is required
For example
endpoints.beans.id=springbeans endpoints.beans.sensitive=false endpoints.shutdown.enabled=trueWhat is the significance of /metrics endpoint ?
This provides snapshot of running application and give many metrics for example memory allotted, heap allocation, thread pool, garbage collector etc
What is the significance of /trace endpoint ?
This provides details of web request for example method, path, request and response header, timestamp etc.
What is the significance of /dump endpoint ?
This provides snapshot of current thread activity
How to deploy spring boot application in external tomcat ?
Spring boot application can be deployed in external tomcat using following steps
given in link.
Deployment Of Spring Boot In External TomcatWhat is the benefit of spring boot ?
It provides following benefit
- Auto Configuration : Spring boot can itself auto configure many configuration like bean injection
- Starter Dependency : It provides complete package of library for any functionality, by this we can be away from version mismatch
- Command line interface : By this we can concentrate only on application code instead of trading code like import , semicolon after each line
- Actuator : By this we can know what's going on inside running application.
What dependency should i include to reload changes without restarting server ?
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.1.5.RELEASE</version>
</dependency>
Comments
Post a Comment