Saturday, July 8, 2017

Database access with Spring boot

The simplest way of creating Spring boot with MySQL application is via Spring starter project using STS (Spring Tool Suite) IDE.

Steps:
  • Create a new project by selecting spring starter project wizard
  • Select project type as Maven, provide project name, packaging, and Java version etc.

  • Select spring boot version and project dependencies

  • After finishing, It will create the project structure with all required dependency.
  • Configure MySQL configuration in application.properties file
  • Now, Create the @Entity model (User) which should be persisted in the database. Hibernate will automatically translate entity class into a table.

  • Create the repository (UserRepository.java). The Repository interface will be automatically implemented by Spring in a bean with the same name with changing case. For UserRepository, the bean name will be userRepository.

  • To handle HTTP request, Create a Controller class (UserController.java) having method POST and GET operations.

  • Now run the SpringBootMySQLApplication.java as a Java application. It will start the tomcat server on default port i.e. 8080
  • Open browser and hit url http://localhost:8080/users

  • As there is no user present into the database that is why we see empty list. Let's add few users using POSTMAN.
  • To add a user, Open Postman and run below http request


  • Congratulations! We've just developed a Spring application which is bound to a MySQL database, Ready for production! Source code can be downloaded from GITHUB.
Happy Coding...!!!

Friday, July 7, 2017

Spring Boot application Example

As we know that there are various ways for creating Spring Boot application. For this sample application, I am going to use STS (Spring Tool Suite) IDE.

Steps:
  • Create a new project by selecting spring starter project wizard


  • Select project type as Maven, provide project name, packaging, and Java version etc.

  • Select spring boot version and project dependencies

  • After finishing, you can see the project structure as shown below

  • Spring boot generates a Java file in the src/main/java directory, pom.xml file with all required dependency. 


  • To handle HTTP request, Create a Controller class

  • Now run the SpringBootExampleApplication.java as a Java application. It will start the tomcat server on default port i.e. 8080

  • Open browser and hit url http://localhost:8080/application
Note:

By Default, Application will start on port 8080 but can override by adding server.port to application.properties file.


Happy Coding..!!!

What is Spring Boot Initilizr?

Spring Boot Initilizr is a web tool which is provided by Spring on official site using which Spring Boot project can be created by providing project details. It simplifies Spring Applications Development by providing initial project structure and build scripts which reduces development time thus increase productivity.
Steps to create Spring Boot project via initilizr
·        Select Maven project and dependencies. Fill other details as shown below and click on generate project.


·        Download the project, extract and now import this project As Maven by using Import option from the STS (Spring Tool Suite) IDE.
·        After finishing, You can see the project structure as shown below:

·    Spring boot generates a Java file in the src/main/java directory, pom.xml file with all required dependency. The default created Java file is the below.

·    Now run this project by selecting Java Application from run options and you will see the following output.


 Happy Coding…!!!

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...