Play Spring MVC (iv)---Integrate JPA in spring MVC

Source: Internet
Author: User

About integrating JPA in spring MVC is based on my last article on Spring MVC Basic configuration, so let's take a look at my previous post:

Next, you need to add some new files:

jdbc.driverclassname=com.mysql.jdbc.driverjdbc.url=jdbc\:mysql\://localhost\:3306/tmos?useunicode\=true& characterencoding\=utf-8&autoreconnect\=truejdbc.user=rootjdbc.password=rootjdbc.dialect= org.hibernate.dialect.mysql5dialectjdbc.show_sql=falsejdbc.format_sql=true#jdbc.dialect= Org.hibernate.dialect.mysqlinnodbdialectjdbc.initialpoolsize=2jdbc.maxpoolsize=200jdbc.batch_size= 1, False 0, yes ' Y ', no ' N '


<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://" xmlns: aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:context= "Http://" xmlns:p= "" xmlns:tx= "Http://" xmlns:xsi= "Http://" xmlns:jpa= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/DATA/JPA" xmlns: Cache= "Http://" xsi:schemalocation= " EANs Context SCHEMA/AOP HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP/SPRING-AOP-3.0.XSDHTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX/SPRING-TX-3.0.XSDHTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/DATA/JPA http:/ / h Ttp:// Chema/cache "> <context:annotation-config/ ><context:component-scan base-package= "module"/> <!--here depending on the project--><!--configuration Placeholder--><beanclass= " Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer "><property name=" Location "value=" Classpath:/ "/></bean><!--data source--><!--<bean id=" DataSource "class=" Org.apache.commons.dbcp.BasicDataSource "destroy-method=" Close "abstract=" false "lazy-init=" Default "autowire=" Def Ault "> <bean id=" dataSource "class=" Org.springframework.jdbc.datasource.DriverManagerDataSource "> <property name= "Driverclassname" value= "${jdbc.driverclassname}"/&Gt;<property name= "url" value= "${jdbc.url}"/><property name= "username" value= "${jdbc.user}"/>< Property name= "Password" value= "${jdbc.password}"/></bean><!--Configure a factory--<bean id= " Entitymanagerfactory "class=" Org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean "> <pro Perty name= "DataSource" ref= "DataSource"/> <property name= "Persistenceprovider" ref= "Persistenceprovider"/&        Gt <property name= "Jpavendoradapter" ref= "Jpavendoradapter"/> <property name= "JpaDialect" ref= "JpaDialect"/ > <property name= "jpaproperties" > <props> <prop key= "Hibernate.dialect" >${jdbc.dialect}</prop> <prop key= "" >${}</prop> <! --Avoid duplicate printing of SQL--<prop key= "Hibernate.show_sql" >${jdbc.show_sql}</prop> <prop key= "   Hibernate.format_sql ">${jdbc.format_sql}</prop>         </props> </property> <property name= "Packagestoscan" ><list><valu e>module.entity</value> </list></property> </bean><bean id= "Persistenceprovider "class=" org.hibernate.ejb.HibernatePersistence "/> <bean id=" jpavendoradapter "class=" org    . springframework.orm.jpa.vendor.HibernateJpaVendorAdapter "> <property name=" Database "value=" MYSQL "/>      </bean> <bean id= "Jpadialect" class= "Org.springframework.orm.jpa.vendor.HibernateJpaDialect"/> <jpa:repositories base-package= "Module.dao" entity-manager-factory-ref= "entitymanagerfactory" Trans action-manager-ref= "Txmanager"/> <!--<bean id= "CacheManager" class= "Org.springframework.cache.ehcach E.ehcachecachemanager "p:cache-manager-ref=" Ehcache "> </bean> <bean id=" Ehcache " Class= "Org.springframewoRk.cache.ehcache.EhCacheManagerFactoryBean "p:config-location=" Classpath:spring-ehcache.xml "/>-- <bean id= "Txmanager" class= "Org.springframework.orm.jpa.JpaTransactionManager" > <property name= "Entitymanagerfactory" ref= "entitymanagerfactory"/> </bean><tx:annotation-driven transaction-ma Nager= "Txmanager"/></beans>
This completes the integration of JPA in spring MVC,Here you can download the project, which contains some test code and the jar package used:

Play Spring MVC (iv)---Integrate JPA in spring MVC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.