Simple Login Application Using Spring MVC and Hibernate – Part 2
I hope you have visited my part1 of my tutorial. Let’s see the steps for integrating hibernate framework into Spring MVC. Here I have used MySQL database. I have created one database called “springmvc” and created one table called “user” with userid, username, password fields.
I have inserted some records into table like this.
Step 1: Creating User POJO class.
We need to create a User POJO class for mapping user table. Ok let’s create it.
Step 2: Creating hibernate mapping xml file for user class.
In hibernate we need to create hibernate mapping xml file for all domain class for mapping into corresponding database table. Instead of creating xml file you can use annotation for mapping domain class into database table. This is my mapping xml document created for mapping our user domain class into user database table.
Step 3: Creating authenticate service class.
The method “verifyUserNameAndPassword” present in “AuthenticateService” class is used for verifying the user name and password details against database table. It simply returns the boolean value.
Very important one is, I am injecting object for “HibernateTemplate” via setter method. So It’s time for defining data source bean, hibernate properties bean, session factory bean , hibernate template bean and our service beans into applicationContext.xml file.
Step 4: Modifying applicationContext.xml.
Here I have configured the beans that are related to hibernate as well as for our service class. Now we need to inject our service class into our controller and we need to call the “verifyUserNameAndPassword” method for verifying user credentials. So let’s see the steps for injecting our authenticate service class into login controller.
Step 5: Modifying Login Controller.
Here @Autowird annotation is used for injecting our service class into our controller.
That’s all. We have completed our development. Let’s do testing. I have deployed this application into apache server. The result of the application is,