Show Topics
Hide Topics

1.Spring Boot Starters

Spring boot Starters are the one-stop-shop for all the Spring and related technology that we need. For example, if you want to get started using Spring and JPA for database access, just include the spring-boot-starter-data-jpa dependency in your project, and you are good to go.

 

All official starters follow a similar naming pattern; spring-boot-starter-*, where is a particular type of application. The following are the some of the application starters are provided by Spring Boot under the org.springframework.boot group

 

Name Description
spring-boot-starter-web-services Starter for using Spring Web Services
spring-boot-starter-web Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container
spring-boot-starter-test Starter for testing Spring Boot applications with libraries including JUnit, Hamcrest and Mockito
spring-boot-starter-jdbc Starter for using JDBC with the Tomcat JDBC connection pool
spring-boot-starter-jersey Starter for building RESTful web applications using JAX-RS and Jersey. An alternative to spring-boot-starter-web
spring-boot-starter-aop Aspect-oriented programming with Spring AOP and AspectJ
spring-boot-starter-security Starter for using Spring Security
spring-boot-starter-data-jpa Starter for using Spring Data JPA with Hibernate
spring-boot-starter Core starter, including auto-configuration support, logging,YML

 

In above Example we used spring-boot-starter & spring-boot-starter-test Starters which are configure in pom.xml

 

 

 

2.@SpringBootApplication Annotation

This annotation marks the class as a spring bean, configures the application by adding all the jars based on the dependencies and also scans the other packages for spring beans.

 

Spring Boot developers always have their main class annotated with @Configuration, @EnableAutoConfiguration and @ComponentScan.

  1. @Configuration                       – Specifies this class as a spring bean
  2. @EnableAutoConfiguration     – This tells how you want to configure Spring, based on the jar dependencies that you have added. & also Enable / Disable auto configuration
  3. @ComponentScan  – is to scan other packages for spring beans.
  4. @Import           – used to import additional configuration classes
  5. @ImportResource       –annotation to load XML configuration files

 

Since these annotations are so frequently used together Spring Boot provides a convenient @SpringBootApplication as an alternative. The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration and @ComponentScan with their default attributes.

@SpringBootApplication = @Configuration + @ComponentScan + @EnableAutoConfiration.

 

The original @SpringBootApplication annotation class is defined as below

 

 

 

3 SpringApplication Class

SpringApplication class is used to bootstrap and launch a Spring application from a Java main method. By default, class will perform the following steps to bootstrap your application:

 

In most circumstances the static run(Object, String[]) method can be called directly from your main method to bootstrap your application:

 

 

 

4. Embaded Servlet containers

The following embedded servlet containers are supported out of the box.By default we will get Tomcat

Name Servlet Version Java Version
Tomcat 8 3.1 Java 7+
Tomcat 7 3.0 Java 6+
Jetty 9.3 3.1 Java 8+
Jetty 9.2 3.1 Java 7+
Jetty 8 3.0 Java 6+
Undertow 1.3 3.1 Java 7+

 

 

 

5.Spring Boot Profiles (@Profile Annotation)

Spring Profiles provide a way to segregate parts of your application configuration and make it only available in certain environments. Any @Component or @Configuration can be marked with @Profile to limit when it is loaded

 

In the normal Spring way, you can use a spring.profiles.active Environment property to specify which profiles are active.

 

You can specify the property in any of the usual ways, for example you could include it in your application.properties:spring.profiles.active=dev,hsqldb or specify on the command line using the switch --spring.profiles.active=dev,hsqldb.

 

 

 

6. Spring Boot Actuator

Spring Boot provides actuator to monitor and manage our application. Actuator is a tool which has HTTP endpoints. when application is pushed to production, you can choose to manage and monitor your application using HTTP endpoints.

 

To get production-ready features, we should use spring-boot-actuator module. We can enable this feature by adding it to the pom.xml file.