Spring Boot

CORS Support

Security that restricts the resources implemented in web browsers is known as Cross-Origin Resource Sharing (CORS). If your web application is running on 8080 port and by using JavaScript you are trying to consume RESTful web services from 9090 port. In such a case, you will face the Cross-Origin Resource Sharing security issue on your web browsers. By using @CrossOrigin annotation on the controller method, we can set the origins for the RESTful web service. This annotation supports specific REST API, and not for the entire application.

There are two pre-requisites to handle this issue −

  • RESTful web services should support Cross-Origin Resource Sharing.
  • RESTful web service applications should allow accessing the API(s) from the 8080 port.

Spring Boot Actuator

To help us monitor and manage a Spring Boot application, the Spring Boot Actuator provides secured endpoints. By default, all actuator endpoints are secure. It helps monitor and manage application when pushed to production. To enable the Spring Boot actuator endpoints in a Spring Boot application, one needs to add the Spring Boot Starter actuator dependency (spring-boot-starter-actuator) in the build configuration file.

The three main features of Spring Boot Actuator are:

  • Endpoints –  It allows one to monitor and interact with the application. Spring Boot also provides a number of built-in endpoints. Some endpoints and their usage –
    • /metrics endpoint is used to view the application metrics. For instance, memory used, memory-free, threads, classes, system uptime, etc.
    • /env endpoint is used to view the list of Environment variables used in the application.
    • /beans endpoint is used to view the Spring beans and its types, scopes, and dependency.
    • /health endpoint is used to view the application health
    • /info endpoint is used to view the information about the Spring Boot application.
    • /trace endpoint is used to view the list of Traces of your Rest endpoints.
  • Metrics – Spring Boot Actuator provides dimensional metrics by integrating with the micrometer. The micrometer is integrated into Spring Boot. It provides vendor-neutral interfaces for timers, gauges, counters, distribution summaries, and long task timers with a dimensional data model.
  • Audit – A flexible audit framework that publishes events to an AuditEventRepository is provided by Spring Boot. It automatically publishes the authentication events if spring-security is in execution.

Spring Boot DevTools

DevTools i.e., Developer Tool aims to try and improve the development time of the Spring Boot application. Spring Boot DevTools picks up any change made and restarts the application. The DevTools always monitor classpath resources. The only way to trigger a restart is to update the classpath. Spring Boot DevTools provides the following features –

  • Property Defaults will disable the caching and allow us to update the pages without restarting the application. But setting up these properties while development always creates some problems.
  • Automatic Restart allows us to reload the Java classes and its configuration at the server-side. It is deployed dynamically after the server-side changes are made, then, the server restarts, and loads the modified code. It is mostly used in microservice-based applications.
  • LiveReload is an embedded server that comes with the Spring Boot DevTools module. It allows an automatic trigger of a browser refresh by the application whenever any changes are made in the resources. We can disable this setting.
  • Remote Debug Tunneling supports Spring Boot to tunnel JDWP (Java Debug Wire Protocol) over HTTP directly to the application.
  • Remote Update and Restart supports remote application updates and restarts. It monitors the local classpath for file changes and pushes them to a remote server, which is then restarted. 

Advantages of Spring Boot

  • Easy to understand.
  • Increases productivity
  • Reduces the cost and development time
  • Flexible enough to configure everything automatically. For instance, Java Beans, XML configurations, and Database Transactions.
  • Auto configured is available for everything; no need for manual configurations.
  • Offers annotation-based spring application
  • Includes Embedded Servlet Container
  • Production-ready features are available. For instance metrics, health checks, and externalized configuration.
  • Reduces or minimizes the writing of boilerplate codes. Here boilerplate codes mean the code that has to be written in many places within our program with little or no alteration.
Scroll to Top