Friday, 28 December 2018

Spring Boot Starters

          In previous post, we discussed how to create the Spring boot application using Spring Intializr. In the current post, we will learn the need of spring boot starters and what are the spring boot starters.

     Starters are a set of convenient dependency descriptors that you can include in your application. You get a one-stop-shop for all the Spring and related technology that you need, without having to hunt through sample code and copy paste loads of dependency descriptors. (Reference :-Spring Doc)

    Spring Boot Starters are just JAR Files. They are used by Spring Boot Framework to provide Automatic Dependency Resolution . It means it will add the convenient dependencies for the application. All starters in spring boot start with spring-boot-starter- .  You can also create your own starter but it shouldn't start with spring-boot-starter-, give some other convenient name(Create Own Starter).

    For example, if you want to get started using Spring and JPA for database access, include the spring-boot-starter-data-jpa dependency in your project. Automatically it will add all the required dependencies for jpa to access the database. 


List of Spring boot starters


1)  spring-boot-starter


This starter contains core starter, including auto-configuration support, logging and YAML.

Add this starter into pom.xml, check the below pom.xml.

<dependencies>
     <dependency>  
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter</artifactId>
    </dependency>
</dependencies>



2) spring-boot-starter-web

    Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container.

pom.xml,(to add this starter)

<dependencies>
     <dependency>  
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>



3) spring-boot-starter-data-jpa

This starter is used to access database for Spring and JPA.

pom.xml,

<dependencies>
     <dependency>  
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
</dependencies>


4) spring-boot-starter-jdbc

This Starter for using JDBC with the HikariCP connection pool.

pom.xml,

<dependencies>
     <dependency>  
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
</dependencies>



5) spring-boot-starter-data-ldap

This Starter for using Spring Data LDAP.

pom.xml,

<dependencies>
     <dependency>  
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-data-ldap</artifactId>
    </dependency>
</dependencies>


6) spring-boot-starter-data-mongodb

This Starter for using MongoDB(NoSQL database) and Spring Data MongoDB.

pom.xml,

<dependencies>
     <dependency>  
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>
</dependencies>



7) spring-boot-starter-security

This starter is using for spring security, to achieve authentication and authorization.

pom.xml,

<dependencies>
     <dependency>  
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
</dependencies>



8) spring-boot-starter-cache

This starter for using Spring Framework’s caching support.

pom.xml,

<dependencies>
     <dependency>  
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-cache</artifactId>
    </dependency>
</dependencies>


9) spring-boot-starter-json

This starter is for reading and writing json data.

pom.xml,

<dependencies>
     <dependency>  
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-json</artifactId>
    </dependency>
</dependencies>



10) spring-boot-starter-test

Starter for testing Spring Boot applications with libraries including JUnit and Mockito.

pom.xml,

<dependencies>
     <dependency>  
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
</dependencies>


11) spring-boot-starter-validation

Starter for using Java Bean Validation with Hibernate Validator.

pom.xml,

<dependencies>
     <dependency>  
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>
</dependencies>

       There are so many other starters also available in spring boot, i have not mentioned here.  Only some of important starters listed above. For other starters you can refer Spring documentation.


Note:- As a developer, I would not need to worry about either these dependencies or their compatible versions.


Related Post:--
1) The @SpringBootApplication Annotation usage and example
2) Advantages of Spring Boot
3) How to create the Spring Boot Project using Spring Initializr tool ?
4) Causes and Solution of NoSuchBeanDefinitionException in Spring.

Monday, 24 December 2018

Database Schema of Hygieia

           As we know that Hygieia uses MongoDB as database to store and retrieve the data. MongoDB is a document-oriented DBMS. It stores the data in terms of collections instead of tables, it's equivalent to tables in RDBMS.

         In this post, we will discuss what are the collections used in the Hygieia and sample screenshots of MongoDB collections.

       The following table gives a list of collections in Hygieia and the corresponding collectors that populate data for each collection,

database schema of hygieia

Some of the sample collections(MongoDB collections) as follows,


pipelines collection:-


pipeline collection in hygieia

Commits collection:-


commits collection in hygieia


builds collection:-


builds collection in hygieia


collector_items collection:--


collector_items collection in hygieia


Thank you for visiting blog.
Have a great day.



Related Posts:--
1) Hygieia Introduction
2) Hygieia Developer Setup
3) Hygieia End User Configuration
4) Hygieia Architecture
5) Collectors in Hygieia
6) DevOps Dashboards

Friday, 14 December 2018

How to Create a Spring Boot Project Using Spring Initializr

         In the previous post, we discussed the usage and examples of the @SpringBootApplication annotation. In this post, we'll learn how to create a Spring Boot application using Spring Initializr.

One of the biggest challenges when getting started with a new framework is the initial project setup, especially if you're starting from scratch without an existing project as a reference. Spring Initializr simplifies this process by generating a ready-to-use Spring Boot project with the required configuration.

        Spring Initializr is a web-based tool provided by Spring that helps you create a Spring Boot application. It is especially useful for beginners, as it generates the initial project structure and configuration, allowing you to focus on developing your application instead of setting up the project manually.


Spring Initialzr URL : Spring Initilazr


Select Maven project and dependencies. Fill other details like Group, Artifact and click on generate project.

I have selected Web, JPA, DevTools and Actuator as dependencies.

Spring Initializr

When click on "Generate Project" , it will ask for download project, will download the zip file.

Extract the downloaded project file, and import into eclipse tool.

Import project in eclipse


Select Existing Maven Project, browse the extracted project directory.



Next,

Browse project directory

The demo project has now been imported into Eclipse.
The project structure looks like the following:




The main class DemoApplication.java,


Spring boot Application class

The pom.xml,

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <parent>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.1.1.RELEASE</version>
      <relativePath/> <!-- lookup parent from repository -->
 </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

 <properties>
       <java.version>1.8</java.version>
 </properties>

 <dependencies>
      <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-actuator</artifactId>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-data-jpa</artifactId>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
      </dependency>

      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-devtools</artifactId>
          <scope>runtime</scope>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-test</artifactId>
          <scope>test</scope>
      </dependency>
 </dependencies>

 <build>
    <plugins>
       <plugin>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-maven-plugin</artifactId>
       </plugin>
    </plugins>
 </build>

</project>

Thank you for visiting blog.


Related Posts:--
1) The @SpringBootApplication Annotation usage and example
2) Explain advantages of Spring Boot
3) Causes and Solution of NoSuchBeanDefinitionException in Spring.
4) Cause and solution of LazyInitializationException in Hibernate

Thursday, 13 December 2018

Spring Boot @SpringBootApplication Annotation: Usage and Example

         In this post, we will learn about the @SpringBootApplication annotation, its purpose, and its usage with an example.

As you may know, a Spring application typically uses the @Configuration, @ComponentScan, and @EnableAutoConfiguration annotations on the main application class to enable various Spring features.

In Spring Boot, instead of using these three annotations separately, we use the @SpringBootApplication annotation on the main application class. This single annotation combines the functionality of:

  • @Configuration for Java-based Spring configuration.

  • @ComponentScan for component scanning.

  • @EnableAutoConfiguration for enabling Spring Boot's auto-configuration feature.


       In short, the @SpringBootApplication annotation combines the functionality of three Spring annotations into a single annotation.

The @SpringBootApplication annotation is equivalent to the following three annotations:

@SpringBootApplication = @Configuration + @ComponentScan + @EnableAutoConfiguration

By using @SpringBootApplication, you can enable Java-based configuration, component scanning, and Spring Boot's auto-configuration with just a single annotation.

Sample Spring Boot Main Class:- 

package com.example.springbootapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication    // same as @Configuration @EnableAutoConfiguration @ComponentScan
public class Application {

          public static void main(String[] args) {
                   SpringApplication.run(Application.class, args);
          }

}


      In a Spring application, you can use the @ComponentScan("com.example") annotation to scan the components in the specified package (com.example).

In Spring Boot, you can override the default component scanning behavior of @SpringBootApplication by specifying the packages to scan using its parameters. For example, you can use the scanBasePackages attribute to define one or more packages that should be scanned for Spring components.

@SpringBootApplication(scanBasePackages = "com.example")

or String array(comma separated)

@SpringBootApplication(scanBasePackages = {"com.example", "com.main"})


Example:-

package com.example.springbootapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = "com.example")
public class Application {

          public static void main(String[] args) {
                     SpringApplication.run(Application.class, args);
          }

}
In the upcoming posts, we will explore more Spring Boot annotations with practical examples.

Thank you for visiting the blog!
Have a great day!


Related Posts:--
1) Explain advantages of Spring Boot
2) Causes and Solution of NoSuchBeanDefinitionException in Spring
3) Cause and solution of LazyInitializationException in Hibernate