Powered by Blogger.

Multiples DATABASE Connection and Data shifting Using Spring Boots API

1 comment :
Multiple DataBase Connection and Data shifting using Spring boot API configuration Example.
Step-by-step Write Java files.
1. application.properties File for Add multiple DataBase Connection. 
2. DBConfigDBNAME.JAVA Files for multiple DataBase Connection. 
3. Job Scheduler.java file for Auto shift programm. 
4. Entity Beans, Repository, Services Implementations for Binding and shifting Data.
  1. Create Spring Boot Java (Microservices)
      Create Spring Boot Java (Microservices).
  1. Project Name: DataShiftingConfigSpringBoots
  2. Group: DataShifting-a143mk
  3. Artifactid: DataShifting-a143mk
  4. Description: DataBase Connection and Data shifting using Spring boot API.
  5. Package: DataShiftinga143mk
Select the technologies and library(Maven Dependency ) to be.
  1. spring-boot-configuration-processor
  2. ojdbc8

while creating the project pom.xml file and some maven dependency, main class is automatically created when web add any dependency like.

pom.xml


1. Configure application.properties


Create DataBase Configuration java Files :
DBConfigDATABASE1.java


DBConfigDATABASE2.java


DBConfigDATABASE3.java

Create Scheduler ClassCreate Scheduler for Auto run Program and import some Packages Scheduler.java as below:

Have you seen the previous post? You all know how to learn and create Entity Bean, Repository, Service Implementation in the project. If you don't know about it then go to the previous post and learn it.

A Rest API with Spring Boot using JSON, MySQL and JPA

2 comments :
Introduction:
In this article will look into how to create a REST API using HTTP methods for Create and Retrieve operations in Spring Boot along with MYSQL database. Spring Boot is an open source Java-based framework to build enterprise spring applications. . 
Overview: 
  • Create MYSQL database From WampServer.
  • Create the Spring Boot Project From STS-4.
  • Create Entity model class.
  • Create JPA Data Repository.
  • Create Service class.
  • Create Rest Controllers class.
  • Run the Project.
  • Testing using Postman.
  • Video Link for watching How to build API.

Create MYSQL database using WampServer.
Download WampServer install and Run-> go to phpMyAdmin and click.  
Open localhost/phpmyadmin/ 
Create Database Name is “hostel”.

Crate Table in hostel Database. Table Name is states with number of fields/Column.

Create Table column name, which is show in image.



Create the Spring Boot Project from STS-4:
It will write project name, group, artifact, version, description, package etc. 

 
Create Entity model class. 
  • Create the States model class to map with the States table.
  • @Entity is used to annotate that the class is an entity in the database.
  • @Table is used to annotate name of table in the database.
  • @id is used to reference that widget to your java file and access it from java file.
  • @GeneratedValue is used to generation strategies for the values of primary keys.
States.java

Create JPA Data Repository. 
  • Create StatsRepository Repository interface extending JPA Repository.
  • There are not need writing any SQL/MySql etc query.
  • @Repository annotation is used to indicate that the class provides the mechanism for storage, retrieval, search, and update and delete operation on objects.
StatsRepository.java

Create Service class. 
  • Create StateService service class to code the business logic and it acts as a middle layer between repository and controller class.
  • @Service annotation is a specialization of @Component annotation. Spring Service annotation can be applied only to classes. It is used to mark the class as a service provider.
  • @Transactional StateService annotate methods are executed in transactions.
    Example:
    @Transactional(readOnly = false, rollbackFor={Throwable.class, Exception.class}, propagation = Propagation.SUPPORTS)
  • @Autowired annotation is used for automatic dependency injection. Spring framework is built on dependency injection and we inject the class dependencies through spring bean configuration file.
StateService.java
Create Rest Controllers class. 
  • Create Rest StateController Controller class which contains all REST API endpoints for Create and Retrieve operations.
  • @RestController annotation was introduced in Spring 4.0 to simplify the creation of REST web services. It's a convenience annotation that combines @Controller and @ResponseBody– which eliminates the need to annotate every request handling method of the controller class with the @ResponseBody annotation.
StateService.java

Run the Project:
Write click to project and Run as->Spring boot App, it will check console to run project success and check running port.  



Testing using Postman.
Execute GET Request method to add a States to the Database. 

 

Video Link for watching How to build API.

Download Project: Download