Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to build spring mvc with spring hibernate?


Asked by Phillip Acosta on Dec 12, 2021 Hibernate



Spring MVC + Spring Boot2 + JSP + JPA + Hibernate 5 + MySQL Example - In this article, we will learn how to develop a Spring MVC web application using Spring MVC, Spring boot 2, JSP, Hibernate 5, JPA, Maven, and MySQL database.
Next,
Hibernate configuration used in the example is based on hibernate Java-based configuration. LocalSessionFactoryBean creates a Hibernate SessionFactory. This is the usual way to set up a shared Hibernate SessionFactory in a Spring application context. EnableTransactionManagement enables Spring’s annotation-driven transaction management capability.
Keeping this in consideration, Using Java Configuration For using Hibernate 5 with Spring, little has changed since Hibernate 4: we have to use LocalSessionFactoryBean from the package org.springframework.orm.hibernate5 instead of org.springframework.orm.hibernate4.
Accordingly,
For our Spring MVC project, we need dependencies for Spring Core, Spring MVC, Hibernate Core, Hibernate Validator, MySql and JSTL and we need to add dependency tags for all these in our pom.xml file so that maven can download the required jars for us.
Moreover,
1. Create database using MySQL. 2. Download source code. 3. Navigate to root directory using command prompt and run maven command as mvn clean package . 4. Install war file in Tomcat 8 5. Run the URL http://localhost:8080/spring-mvc/personform