Introduction to Spring Boot JPA with REST using TDD


Intermediate level Java course lab

 I. Introductions

Spring Boot is an easy to framework. Here, JPA framework shall be used to store and retrieve data in a relational database. This will be coupled with an in-memory database H2 for the ease of database connectivity. This is important topic for Pivotal Spring Professional Certification for core java training in Delhi in the current IT industry.

 II. Software Tools

This lab is provided with the following tools, however any newer versions can be used for accomplishing this lab:
  • Java platform - version 8.151
  • IntelliJ IDE - version 2017.2.6
  • Maven for dependency management - version 3
These software tools are most widely used in IT industry for advance java training in Delhi and for java projects.

III. Aim

The purpose of this lab is to create a simple web application which allows a user to register their information and later retrieve it as well. We are going to achieve this through a RESTful spring boot application because it is a great library which hides a lot of webmvc integration and allows the programmer to focus on code only. This lab help students gain more knowledge to prepare for java certification in Delhi.

IV. Lab Instructions

Maven Dependencies

Maven is used here for dependency management here. It is very useful to maintain a proper code structure as well.
Add the following dependencies.
  

Swagger

This is an excellent library that allows visualisation of RESTful calls. It also provides the CURL equivalent command in case that is preferable. It is a good example of live documentation of the code as well. It is important library used for Java training in Delhi.
  1. Create a new config class with @EnableSwagger2 annotation.
On running the application now, Swagger is being rendered /swagger-ui.html endpoint.

JPA Entity

Create the User JPA entity by annotating it with @Entity as follows:

The @NonNull validations ensure that the Entity cannot be created with null values and will throw up runtime ConstraintViolationException when trying to insert a record with null values.

JPA Repository

JPA repository is very short and simple with a method for querying. We don’t need to write more code as spring takes care of it. This will create proper SQL queries behind the scenes.


REST Controller

This class allows us to add the REST endpoints through which we can send and retrieve user information. Again, we are using boilerplate Spring REST code peppered with Lombok annotations.

Verification

  1. Run the application either through maven or IntelliJ Application run config.
  2. Swagger UI shows the controller methods.
  3. Register a user through the UI
  4. Check the response has status code 200.
  5. Now, retrieve the saved user.
  6. Check the response.


  7. Codec Networks provides IT Trainings from EC Council CEH ECSA, LPT, CHFI, Network Security, Penetration Testing, ISACA, ISC2, PECB ISO 27001LA LI, Cisco Networking CCNA CCNP, Linux Administration RHCE, Prog Languages JAVA, Advanced Java, android development. We also offer B2B Industry Solutions and Services in IT | Information|Cyber Security in Delhi NCR India.

Comments

  1. Hello There,


    That’s how speedy and easy this read was! Looking forward to more of such powerful content on Introduction to Spring Boot JPA!

    I wrote a simple c program to read the each character from the text file which is saved in desktop and display in console window . I am using Visual c++(2008).At first I used to get other error when I compiled. Now am getting error spawing :cmd.exe. I googled a lot and could find some setting in VC++ directories.

    Tools->options->projetcs & soultions->VC++-> then set the three things $(SystemRoot)\System32,$(SystemRoot)\System32\wbem,$(SystemRoot).but still could get ride of the same error. Please suggest me any advice to remove this error.

    Follow my new blog if you interested in just tag along me in any social media platforms!


    Obrigado,
    Leena

    ReplyDelete
  2. Hi There,

    Great post. Well though out. This piece reminds me when I was starting out Software Tools after graduating from college.


    I'm new to linux and I just had a few questions. I've been doing some of my own research and I was wondering about the pros and cons of dual booting versus a virtual machine and I'm kinda stuck on if I want ubuntu, fedora or mint. I'm running windows seven right now so I was also wondering what linux distro works best with that.

    Awesome! Thanks for putting this all in one place. Very useful!


    Kind Regards,
    Radhey

    ReplyDelete

Post a Comment