- Advantages of SpringBoot
- Convention over configuration; makes development faster
- Embedded containers (tomcat or jetty server); dont have to deploy them
- lots of starter project; easy maven intergration, no version mismatch
- reduces boilerplate code
- create sample application quickly using sprint boot initializer
- How can you spring boot application on custom port?
- Mention server.port in application.properties configuration file. Default port is 8080.
- How can you override default properties in spring boot?
- Default properties can be overridden using application.properties configuration file. Like server.port
- What are the disadvantages of using SpringBoot?
- What is actuator in spring boot?
- Helps to access current state of running application in production.
- Provides REST endpoints to access various metrices like free memory, processors, uptime.
- /metrics: includes free memory, processors
- /health
- /info
- How can you implement spring security in spring application?
- add spring-boot-starter-security in pom.xml
- create a spring config class that extends WebSecurityConfigureAdapter and overrides methods in it.
- What is @SpringBootApplication annotation?
- was introduced in Springboot 1.2
- needs to be added in main class
- replaces 3 annotations used earlier: @Configuration, @ComponentScan, @EnableAutoConfiguration
- Why to use sprig cloud?
- Spring cloud provides tool to developers to develop distributed system (eg: configuration management, service registration, fault tolerance using circuit breaker, distributed tracing etc.)
- Leverage Netflix OSS
- Which version of spring boot have u used?
- version 1.3
- How can u enable logging in sprig boot application?
- Spring boot come with support Log4J2, log back and is pre-configured as Console output
- To enable logging add logging.level in application.properties
- logging.level.spring.framework=Debug
- What are starters?
- we can add starters in pom.xml dependency section
- all dependent jar gets downloaded, no version issues
- A few starters
- spring-boot-starter-web
- spring-boot-starter-test
- spring-boot-starter-security
- spring-boot-starter-jdbc
- spring-boot-starter-logging
- What is the use of spring-boot-maven-plugin?
- this plugin provides commands to run springboot application
- spring-boot:run
- spring-boot:start
- spring-boot:stop
- spring-boot:repackage
- this plugin provides commands to run springboot application
- How can we enable auto reload of spring boot application?
- By using Spring Boot Development Tools; add dependency(spring-boot-devtools) in pom.xml
- when files changes in classpath, application using spring-boot-devtools will get restarted
- How can we use jetty instead of tomcat?
Remove the existing dependency on spring-boot-starter-web and add these in.<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency>
- What is transitive dependency resolution management?
- If "A" is dependent on "B" and "B" is dependent on "C". Then "A" is also dependent on "C"
- Build tool like maven downloads all 3 jars to application classpath
- Spring boot uses this to resolve dependencies
- What is the use of profiles?
- Way to handle different environments (DEV, QA, PROD)
- We can have different properties for diff env. For example, use different DB for each environment
- Mention active profile using spring.profiles.active in application.properties
- What is the best way to expose custom configuration in Spring boot?
- define a configuration component using @ConfigurationProperties
@Component @ConfigurationProperties("basic") public class BasicConfiguration { private boolean value; private String message; private int number;
- The values can then be configured in application.properties
basic.value=true basic.message="testing" basic.number=10