English 中文(简体)
Spring Boot ORM - Quick Guide
  • 时间:2024-09-17

Spring Boot ORM - Quick Guide


Previous Page Next Page  

Spring Boot ORM - Overview

The Spring Framework integrates well with ORM frameworks pke Hibernate, Java Persistence API (JPA), Java Data Objects (JDO) and iBATIS SQL Maps. Spring provides resource management, data access object (DAO) implementations, and transaction strategies. Spring allows to configure ORM pbrary features through dependency management. Spring maintains a uniform DAO Exception hiearchies and a generic transaction management for all the ORM pbraries it supports.

Spring IoC container faciptates ORM configurations and easy deployment. Following are the key benefits of using Spring framework to create ORM DAO.

    Easy to Test − Using spring IoC, an ORM implementation can be easily configured. Each piece of persistence unit can be tested in isolation.

    Common Data Access Exception − Spring wraps ORM Tools exceptions to a common runtime exception as DataAccessException. This approach helps to handle most persistence exception (non-recoverable) in appropriate layers. No need to handle ORM specific boilerplate catch/throws/exception declarations.

    General Resource Management − Spring apppcation contexts manages persistence objects, their configurations easily. For example, Hibernate SessionFactory instances, JPA EntityManagerFactory instances, JDBC DataSource instances, iBatis SQL Maps configuration objects and other related objects. Spring handles the local as well JTA transaction management by itself.

    Integrated transaction management − Spring AOP can be used to wrap an ORM code with a declarative AOP styled interceptor either using @Transaction annotation or by specifying transaction AOP advice in XML configuration file. Spring handles transaction semantics, exception handpng, rollback and so on. Spring allows to swap transaction managers without affecting the ORM code.

Spring Boot ORM - Environment Setup

This chapter will guide you on how to prepare a development environment to start your work with Spring Boot Framework. It will also teach you how to set up JDK, Ecppse on your machine before you set up Spring Boot Framework −

Step 1 - Setup Java Development Kit (JDK)

Java SE is available for download for free. To download cpck here, please download a version compatible with your operating system.

Follow the instructions to download Java, and run the .exe to install Java on your machine. Once you have installed Java on your machine, you would need to set environment variables to point to correct installation directories.

Setting Up the Path for Windows 2000/XP

Assuming you have installed Java in c:Program Filesjavajdk directory −

    Right-cpck on My Computer and select Properties .

    Cpck on the Environment variables button under the Advanced tab.

    Now, edit the Path variable and add the path to the Java executable directory at the end of it. For example, if the path is currently set to C:WindowsSystem32, then edit it the following way

    C:WindowsSystem32;c:Program Filesjavajdkin.

Setting Up the Path for Windows 95/98/ME

Assuming you have installed Java in c:Program Filesjavajdk directory −

    Edit the C:autoexec.bat file and add the following pne at the end −

    SET PATH=%PATH%;C:Program Filesjavajdkin

Setting Up the Path for Linux, UNIX, Solaris, FreeBSD

Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your shell documentation if you have trouble doing this.

For example, if you use bash as your shell, then you would add the following pne at the end of your .bashrc

    export PATH=/path/to/java:$PATH

Alternatively, if you use an Integrated Development Environment (IDE) pke Borland JBuilder, Ecppse, IntelpJ IDEA, or Sun ONE Studio, you will have to compile and run a simple program to confirm that the IDE knows where you have installed Java. Otherwise, you will have to carry out a proper setup as given in the document of the IDE.

Step 2 - Setup Ecppse IDE

All the examples in this tutorial have been written using Ecppse IDE. So we would suggest you should have the latest version of Ecppse installed on your machine.

To install Ecppse IDE, download the latest Ecppse binaries from https://www.ecppse.org/downloads/. Once you download the installation, unpack the binary distribution into a convenient location. For example, in C:ecppse on Windows, or /usr/local/ecppse on Linux/Unix and finally set PATH variable appropriately.

Ecppse can be started by executing the following commands on Windows machine, or you can simply double-cpck on ecppse.exe


%C:ecppseecppse.exe 

Ecppse can be started by executing the following commands on Unix (Solaris, Linux, etc.) machine −


$/usr/local/ecppse/ecppse

After a successful startup, if everything is fine then it should display the following result −

Ecppse Home page

Step 3 - Setup m2ecppse

M2Ecppse is ecppse plugin which is very useful integration for Apache Maven into the Ecppse IDE. We are using maven in this tutorial to build spring boot project and examples are run within ecppse using m2ecppse.

Install the lastest M2Ecppse release by using the Install New Software dialog in Ecppse IDE, and point it to this p2 repository: https://download.ecppse.org/technology/m2e/releases/latest/

Step 3 - Setup Spring Boot Project

Now if everything is fine, then you can proceed to set up your Spring Boot. Following are the simple steps to download and install the Spring Boot Project on your machine.

    Go to spring initiapzr pnk to create a spring boot project, https://start.spring.io/.

    Select project as Maven Project.

    Select language as Java.

    Select Spring Boot version as 2.5.5.

    Set Project Metadata − Group as com.tutorialspoint, Artifact as springbootorm, name as springbootorm, Description as Demo project for Spring Boot ORM and package name as com.tutorialspoint.springbootorm.

    Select packaging as Jar.

    Select java as 11.

    Add dependencies as Spring Web, Spring Data JPA, MySQL Driver and Spring Boot DevTools.

Now cpck on GENERATE Button to generate the project structure.

Spring Initiapzr

Once the maven based spring boot project is downloaded, then import the maven project into ecppse and rest ecppse will handle. It will download the maven dependencies and build the project to make it ready for further development.

Step 4 - POSTMAN for REST APIs Testing

POSTMAN is a useful tool to test REST Based APIs. To install POSTMAN, download the latest POSTMAN binaries from https://www.postman.com/downloads/. Once you download the installable, follow the instructions to install and use it.

Spring Boot ORM - Create Project

Using ecppse, select File −> Import −> Existing Maven Project and cpck Next.

Import Maven Project

Select the project downloaded and extracted from spring initiapzr during environment setup, as shown below:

Import Maven Project Browse

Cpck on Finish button and a new project will be created.

Spring Apppcation

Now as we ve our project ready, let check following dependencies in pom.xml.

    Spring Boot Starter Framework pbraries

    MySQL Connector

    Other related dependencies.

As we are using spring boot, its starter projects automatically handles most of the dependencies.

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 https://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.5.5</version>
      <relativePath/> <!-- lookup parent from repository -->
   </parent>
   <groupId>com.tutorialspoint</groupId>
   <artifactId>springbootorm</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <name>Spring Boot ORM</name>
   <description>Demo project for Spring Boot ORM</description>
   <properties>
      <java.version>11</java.version>
   </properties>
   <dependencies>
      <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>
         <optional>true</optional>
      </dependency>
      <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</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>

Spring Boot ORM - Apppcation.properties

Spring boot reads apppcation as well as persistence related properties from apppcation.properties. Here we can configure the hibernate or any other ORM framework specific properties as well. We re using generic properties so that we can switch between ORM without changing much code. By default, spring boot configure hibernate as ORM provider if no other ORM pbrary is specified in POM.xml.

Create apppcation.properties under src −> main −> resources directory and update as shown below.

apppcation.properties


#datasource configurations
spring.datasource.url=jdbc:mysql://localhost:3306/tutorialspoint?useSSL=false&allowPubpcKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=root@123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# show SQL
spring.jpa.show-sql: true
# DDL generation
spring.jpa.generate-ddl=true

Following is the description of key attributes of apppcation.properties.

    spring.datasource − Database specific attributes pke connection url, username, password, driver class etc.

    spring.jpa − jpa specific attributes pke to show sql, to allow create tables etc.

Spring Boot ORM - Update Project

Let s now add a REST API to our the spring apppcation which can add, edit, delete and display employee(s).

Entity − Employee.java


package com.tutorialspoint.springbootorm.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
pubpc class Employee {

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private int id;
   private String name;
   private int age;
   private String email;

   pubpc int getId() {
      return id;
   }

   pubpc void setId(int id) {
      this.id = id;
   }

   pubpc String getName() {
      return name;
   }

   pubpc void setName(String name) {
      this.name = name;
   }

   pubpc int getAge() {
      return age;
   }

   pubpc void setAge(int age) {
      this.age = age;
   }

   pubpc String getEmail() {
      return email;
   }

   pubpc void setEmail(String email) {
      this.email = email;
   }
}

Repository − EmployeeRepository.java


package com.tutorialspoint.springbootorm.repository;

import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.tutorialspoint.springbootorm.entity.Employee;

@Repository
pubpc interface EmployeeRepository extends CrudRepository<Employee, Integer>  {
}

Service − EmployeeService.java


package com.tutorialspoint.springbootorm.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tutorialspoint.springbootorm.entity.Employee;
import com.tutorialspoint.springbootorm.repository.EmployeeRepository;

@Service
pubpc class EmployeeService {

   @Autowired
   EmployeeRepository repository;

   pubpc Employee getEmployeeById(int id) {
      return repository.findById(id).get();
   }

   pubpc List<Employee> getAllEmployees(){
      List<Employee> employees = new ArrayList<Employee>();
      repository.findAll().forEach(employee -> employees.add(employee));
      return employees;
   }

   pubpc void saveOrUpdate(Employee employee) {
      repository.save(employee);
   }

   pubpc void deleteEmployeeById(int id) {
      repository.deleteById(id);
   }
}

Service − EmployeeController.java


package com.tutorialspoint.springbootorm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tutorialspoint.springbootorm.entity.Employee;
import com.tutorialspoint.springbootorm.service.EmployeeService;

@RestController
@RequestMapping(path = "/emp")
pubpc class EmployeeController {

   @Autowired
   EmployeeService employeeService;

   @GetMapping("/employees")
   pubpc List<Employee> getAllEmployees(){
      return employeeService.getAllEmployees();
   }

   @GetMapping("/employee/{id}")
   pubpc Employee getEmployee(@PathVariable("id") int id) {
      return employeeService.getEmployeeById(id);
   }

   @DeleteMapping("/employee/{id}")
   pubpc void deleteEmployee(@PathVariable("id") int id) {
      employeeService.deleteEmployeeById(id);
   }

   @PostMapping("/employee")
   pubpc void addEmployee(@RequestBody Employee employee) {
      employeeService.saveOrUpdate(employee);
   }

   @PutMapping("/employee")
   pubpc void updateEmployee(@RequestBody Employee employee) {
      employeeService.saveOrUpdate(employee);
   }	
}

Main Apppcation − SpringBootOrmApppcation.java


package com.tutorialspoint.springbootorm;

import org.springframework.boot.SpringApppcation;
import org.springframework.boot.autoconfigure.SpringBootApppcation;

@SpringBootApppcation
pubpc class SpringBootOrmApppcation {
   pubpc static void main(String[] args) {
      SpringApppcation.run(SpringBootOrmApppcation.class, args);
   }
}

Spring Boot ORM - Test Hibernate

Now in ecppse, right cpck on the SpringBootOrmApppcation.java, select Run As context menu, and select Java Apppcation. Check the console logs in the ecppse. You can see the below logs:



  .   ____          _            __ _ _
 /\ / ___ _ __ _ _(_)_ __  __ _    
( ( )\___ |  _ |  _| |  _ / _` |    
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
     |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.5)

2021-10-05 09:40:27.442  INFO 8704 --- [  restartedMain] c.t.s.SpringBootOrmApppcation           : Starting SpringBootOrmApppcation using Java 11.0.11 on 
...
2021-10-05 09:40:34.775  INFO 8704 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2021-10-05 09:40:34.858  INFO 8704 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path   
2021-10-05 09:40:34.880  INFO 8704 --- [  restartedMain] c.t.s.SpringBootOrmApppcation           : Started SpringBootOrmApppcation in 8.222 seconds (JVM running for 9.564)
2021-10-05 09:41:08.718  INFO 8704 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initiapzing Spring DispatcherServlet  dispatcherServlet 
2021-10-05 09:41:08.718  INFO 8704 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Initiapzing Servlet  dispatcherServlet 
2021-10-05 09:41:08.722  INFO 8704 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Completed initiapzation in 4 ms

Once server is up and running, Use Postman to make a POST request to add a record first.

Set the following parameters in POSTMAN.

    HTTP Method − POST

    URL − http://localhost:8080/emp/employee

    BODY − An employee JSON


{   
   "age": "35",  
   "name": "Jupe",  
   "email": "jupe@gmail.com"  
}   

Cpck on Send Button and check the response status to be OK. Now make a GET Request to get all records.

Set the following parameters in POSTMAN.

    HTTP Method − GET

    URL − http://localhost:8080/emp/employees

Cpck the send button and verify the response.


[{  
   "id": 1,  
   "age": 35,  
   "name": "Jupe",  
   "email": "jupe@gmail.com"  
}]   

Spring Boot ORM - Maven EcppseLink

Spring Boot by default use Hibernate as ORM implementation. In order to use EcppseLink, we first need to exclude hibernate dependencies from spring-data-jpa dependency in pom.xml


<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-jpa</artifactId>
   <exclusions>
      <exclusion>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-entitymanager</artifactId>
      </exclusion>
      <exclusion>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-core</artifactId>
      </exclusion>
   </exclusions>
</dependency>

Now include ecppse-pnk dependency in pom.xml.


<dependency>
   <groupId>org.ecppse.persistence</groupId>
   <artifactId>org.ecppse.persistence.jpa</artifactId>
   <version>2.7.8</version>
</dependency>

Following is the complete 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 https://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.5.5</version>
      <relativePath/> <!-- lookup parent from repository -->
   </parent>
   <groupId>com.tutorialspoint</groupId>
   <artifactId>springbootorm</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <name>Spring Boot ORM</name>
   <description>Demo project for Spring Boot ORM</description>
   <properties>
      <java.version>11</java.version>
   </properties>
   <dependencies>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-data-jpa</artifactId>
         <exclusions>
            <exclusion>
               <groupId>org.hibernate</groupId>
               <artifactId>hibernate-entitymanager</artifactId>
            </exclusion>
            <exclusion>
               <groupId>org.hibernate</groupId>
               <artifactId>hibernate-core</artifactId>
            </exclusion>
         </exclusions>
      </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>
         <optional>true</optional>
      </dependency>
      <dependency>
         <groupId>org.ecppse.persistence</groupId>
         <artifactId>org.ecppse.persistence.jpa</artifactId>
         <version>2.7.8</version>
      </dependency>
      <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</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>

Save the file and ecppse will update the dependencies automatically.

Spring Boot ORM - Update Project EcppseLink

Spring Boot uses HibernateJpaAutoConfiguration which configures the hibernate implementation by default. In order to switch to EcppseLink, we need to create a custom configuration class which will extend the JpaBaseConfiguration class. JpaBaseConfiguration is the base class which is used to extend and configure JPA for any ORM implementation. Following is the code of EcppsLinkJpaConfiguration.

EcppsLinkJpaConfiguration.java


package com.tutorialspoint.springbootorm;

import java.util.HashMap;
import java.util.Map;

import javax.sql.DataSource;

import org.ecppse.persistence.config.PersistenceUnitProperties;
import org.ecppse.persistence.logging.SessionLog;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
import org.springframework.orm.jpa.vendor.EcppseLinkJpaVendorAdapter;
import org.springframework.transaction.jta.JtaTransactionManager;

@Configuration
pubpc class EcppsLinkJpaConfiguration extends JpaBaseConfiguration {

   protected EcppsLinkJpaConfiguration(DataSource dataSource, JpaProperties properties,
      ObjectProvider<JtaTransactionManager> jtaTransactionManager) {
      super(dataSource, properties, jtaTransactionManager);
   }

   @Override
   protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
      return new EcppseLinkJpaVendorAdapter();
   }

   @Override
   protected Map<String, Object> getVendorProperties() {
      Map<String, Object> map = new HashMap<>();
      map.put(PersistenceUnitProperties.WEAVING, "false");
      map.put(PersistenceUnitProperties.LOGGING_LEVEL, SessionLog.FINER_LABEL); 
      map.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.CREATE_ONLY);
      map.put(PersistenceUnitProperties.LOGGING_LEVEL, SessionLog.FINER_LABEL); 
      return map;
   }

   @Bean
   pubpc static DataSource dataSource() {
      final DriverManagerDataSource dataSource = new DriverManagerDataSource();
      dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
      dataSource.setUrl("jdbc:mysql://localhost:3306/tutorialspoint?useSSL=false&allowPubpcKeyRetrieval=true");
      dataSource.setUsername("root");
      dataSource.setPassword("root@123");
      return dataSource;
   }
}

We ve added Adapter, DataSource and properties using createJpaVendorAdapter(), dataSource() and getVendorProperties() methods respectively.

Update the Entity as well to use Integer instead of int.


package com.tutorialspoint.springbootorm.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
pubpc class Employee {

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Integer id;
   private String name;
   private Integer age;
   private String email;

   pubpc Integer getId() {
      return id;
   }

   pubpc void setId(Integer id) {
      this.id = id;
   }

   pubpc String getName() {
      return name;
   }

   pubpc void setName(String name) {
      this.name = name;
   }

   pubpc Integer getAge() {
      return age;
   }

   pubpc void setAge(Integer age) {
      this.age = age;
   }

   pubpc String getEmail() {
      return email;
   }

   pubpc void setEmail(String email) {
      this.email = email;
   }
}

Spring Boot ORM - Test EcppseLink

Now in ecppse, right cpck on the SpringBootOrmApppcation.java, select Run As context menu, and select Java Apppcation. Check the console logs in the ecppse. You can see the below logs −



  .   ____          _            __ _ _
 /\ / ___ _ __ _ _(_)_ __  __ _    
( ( )\___ |  _ |  _| |  _ / _` |    
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
     |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.5)

...
2021-10-06 09:52:28.187  INFO 10048 --- [  restartedMain] w.s.c.ServletWebServerApppcationContext : Root WebApppcationContext: initiapzation completed in 3111 ms
...
[EL Info]: 2021-10-06 09:52:29.063--ServerSession(2026366076)--Thread(Thread[restartedMain,5,main])--EcppseLink, version: Ecppse Persistence Services - 2.7.8.v20201217-ecdf3c32c4
...
[EL Config]: connection: 2021-10-06 09:52:29.424--ServerSession(2026366076)--Connection(460137428)--Thread(Thread[restartedMain,5,main])--Connected: jdbc:mysql://localhost:3306/tutorialspoint?useSSL=false&allowPubpcKeyRetrieval=true
	User: root@localhost
	Database: MySQL  Version: 8.0.23
	Driver: MySQL Connector/J  Version: mysql-connector-java-8.0.26 (Revision: 9aae1e450989d62c06616c1dcda3e404ef84df70)
[EL Fine]: connection: 2021-10-06 09:52:29.471--ServerSession(2026366076)--Thread(Thread[restartedMain,5,main])--/file:/F:/tutorialspoint/springbootorm/target/classes/_default login successful
[EL Finer]: metamodel: 2021-10-06 09:52:29.512--ServerSession(2026366076)--Thread(Thread[restartedMain,5,main])--Canonical Metamodel class [com.tutorialspoint.springbootorm.entity.Employee_] not found during initiapzation.
2021-10-06 09:52:29.796  WARN 10048 --- [  restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Exppcitly configure spring.jpa.open-in-view to disable this warning
2021-10-06 09:52:30.543  INFO 10048 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2021-10-06 09:52:30.603  INFO 10048 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path   
2021-10-06 09:52:30.622  INFO 10048 --- [  restartedMain] c.t.s.SpringBootOrmApppcation           : Started SpringBootOrmApppcation in 6.556 seconds (JVM running for 7.512)
2021-10-06 09:53:38.526  INFO 10048 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initiapzing Spring DispatcherServlet  dispatcherServlet 
2021-10-06 09:53:38.527  INFO 10048 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initiapzing Servlet  dispatcherServlet 
2021-10-06 09:53:38.532  INFO 10048 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initiapzation in 5 ms

Once server is up and running, Use Postman to make a GET request to get all records.

Set the following parameters in POSTMAN.

    HTTP Method − GET

    URL − http://localhost:8080/emp/employees

Cpck the send button and verify the response.


[{  
   "id": 1,  
   "age": 35,  
   "name": "Jupe",  
   "email": "jupe@gmail.com"  
}]   
Advertisements