Spring Boot – Part1

JAVA, TECHNOLOGY

Spring Boot

Spring Boot is an open source Java-based framework used to create Micro Services. It is used to build stand-alone and production ready spring applications.

What is Micro Service?

Micro Service is an architecture that allows the developers to develop and deploy services independently. Each service running has its own process, and this achieves the lightweight model to support business applications.

Features and benefits of Spring Boot

  • Spring boot provides a flexible way to configure Java Beans, XML configurations, and Database Transactions.
  • It provides a powerful batch processing and manages REST endpoints.
  • In Spring Boot, everything is auto configured; no manual configurations are needed.
  • It offers annotation-based spring application.
  • Eases dependency management.
  • It includes Embedded Servlet Container.
  • It is highly dependent on the starter templates feature.

How Spring Boot works

Spring Boot automatically configures our application based on the dependencies we have added to the project by using @EnableAutoConfiguration annotation. For example, if MySQL database is on our classpath, but we have not configured any database connection, then Spring Boot auto-configures an in-memory database.

Spring Boot Starters

Handling dependency management is a difficult task for big projects. Spring Boot resolves this problem by providing a set of dependencies for developer’s convenience.

For example, if we want to create a web application with REST Endpoints, it is sufficient if we include spring-boot-starter-web dependency in our project.

Note that all Spring Boot starters follow the same naming pattern spring-boot-starter-*, where * indicates that it is a type of the application.

Example:

Spring Boot Starter Test dependency is used for writing Test cases. Its code is shown below:

                  org.springframework.boot
          spring-boot-starter-test
                
        

Spring Boot Application

The entry point of the Spring Boot Application is the class containing @SpringBootApplication annotation. This class should have the main method to run the Spring Boot application. @SpringBootApplication annotation includes @EnableAutoConfiguration, @ComponentScan, and @SpringBootConfiguration annotations.

Spring Boot automatically scans all the components included in the project by using @ComponentScan annotation.

Observe the following code for a better understanding:

                
        import org.springframework.boot.SpringApplication;
        import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
        
        @SpringBootApplication
        public class DemoApplication {
        public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
        }
                
        

Spring Boot – Quick Start – using Groovy

The Spring Boot CLI is a command line tool and it allows us to run the Groovy scripts. Create a simple groovy file which contains the Rest Endpoint script.

Hello.groovy

                
        @Controller
        class Example {
        @RequestMapping("/")
        @ResponseBody
        public String hello() {
        "Hello Spring Boot"
        }
        }
                
        

The above file can be run using the command “spring run Hello.groovy”

spring_command_img

Once we run the groovy file, required dependencies will download automatically and it will start the application in Tomcat 8080 port as shown in the screenshot above. You can also see that sping ‘Mapped "{[/]}" onto public java.lang.String Example.hello()’.

We can go to the web browser and hit the URL http://localhost:8080/, and see the output from hello() function as shown below:

hello_spring_img

Click here to continue >>

Share this:

Take a look at the lastest aricles

In today's fast-paced enterprise world, the pressure is on to create workflows that are not just efficient, but truly intelligent and scalable. Gone are the days when clunky, form-based interfaces could keep up. They were rigid, often frustrating for users, and crucially, lacked the smarts needed to drive real productivity. But what if your forms […]

Are outdated HR processes holding your enterprise back? In today's hyper-competitive landscape, the efficiency of your human resources directly impacts your bottom line, employee satisfaction, and ability to attract top talent. Yet, many organizations are still grappling with manual, resource-intensive tasks that drain productivity and stifle growth. Imagine a world where: Crafting compelling job descriptions […]

In today's hyper-competitive digital landscape, delivering an exceptional user experience (UX) isn't just a nice-to-have – it's the bedrock of customer loyalty and business growth. But as customer behaviors constantly evolve and applications grow increasingly complex, a critical question emerges: How can organizations consistently measure, monitor, and elevate the user experience at scale, and in […]

Let’s shape your AI-powered future together.

Partner with CloudIQ to achieve immediate gains while building a strong foundation for long-term, transformative success.