Spring +spring+ Hibernate configuration 1

Source: Internet
Author: User

This configuration is the spring, SPRINGMVC, hibernate three modules are configured separately, cross-reference! Hibernate connection configuration using the. properties file

Web. XML configuration

<web-app xmlns= "Http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd "version=" 3.1 "metadata-complete=" true "><display-name>archetype Created Web application</display-name ><!--Spring MVC servlet--><servlet><servlet-name>springmvc</servlet-name>< servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class><init-param>< param-name>contextconfiglocation</param-name><param-value>classpath:spring-mvc.xml</ Param-value></init-param><load-on-startup>1</load-on-startup><async-supported>true </async-supported></servlet><servlet-mapping><servlet-name>springmvc</servlet-name ><!--here can be configured as *.do, corresponding to the struts suffix habit--><url-pattern>/</url-pattern></servlet-mapping> <welCome-file-list><welcome-file>/index.jsp</welcome-file></welcome-file-list></web-app >

  

Spring.xml

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xmlns:context= "Http://www.springframework.org/schema/context" xmlns:mvc= "Http://www.springframework.org/schema/mvc" xsi: schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/sche                            Ma/beans/spring-beans-3.1.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context/spring-context-3.1.xsd HTTP://WWW.SPRINGF Ramework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd "><!- -Introduction of properties File--<context:property-placeholder location= "classpath:config.properties"/> <import resource= "Classpath:spring-hibernate.xml"/><!--automatic scanning--><contExt:component-scan base-package= "Com.service"/></beans> 

  

Springmvc.xml

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" Xmlns:xs I= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xmlns:context= " Http://www.springframework.org/schema/context "xmlns:mvc=" Http://www.springframework.org/schema/mvc "Xsi:schemal ocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/bean                            S/spring-beans-3.1.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context/spring-context-3.1.xsd Http://www.springframewor                          K.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd "> <mvc:annotation-driven/> <mvc:default-servlet-handler/> <!--automatically scan the package to make SPRINGMVC think The class with the @controller annotation under the package is the controller--     <context:component-scan base-package= "Com.controller"/> <!--define the prefix of the jump file, view mode configuration--&L T;bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <!--here the configuration I understand is automatically given back actio N method return string prefixed with prefix and suffix, becomes an available URL address--<property name= "prefix" value= "/web-inf/jsp/"/> &LT;PR   Operty name= "suffix" value= ". jsp"/> </bean> </beans>

  

Spring_hibernate.xml

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns:aop= " Http://www.springframework.org/schema/aop "xsi:schemalocation=" Http://www.springframework.org/schema/beans http ://www.springframework.org/schema/beans/spring-beans-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX/http Www.springframework.org/schema/tx/spring-tx-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP/HTTP Www.springframework.org/schema/aop/spring-aop-3.0.xsd "><!--JNDI (Tomcat) to configure the data source--><!--<bean id= "DataSource" class= "Org.springframework.jndi.JndiObjectFactoryBean" > <property name= "jndiname" value= "${ Jndiname} "></property> </bean>--><!--Configuring the data source--><bean name=" DataSource "class=" Com.alibaba.druid.pool.DruidDataSource "init-method=" Init "destroy-method=" close "><property name=" url "value = "${jDbc_url} "/><property name=" username "value=" ${jdbc_username} "/><property name=" password "value=" ${jdbc _password} "/><!--initialize connection size--><property name=" initialsize "value=" 0 "/><!--Connection pool Maximum number of connections used-->< Property Name= "Maxactive" value= "/><!--connection Pool max idle--><property name=" Maxidle "value="/><!-- Connection pool min idle--><property name= "Minidle" value= "0"/><!--get connection Max wait time--><property name= "maxwait" value= " 60000 "/><!--<property name=" poolpreparedstatements "value=" true "/> <property name=" Maxpoolpreparedstatementperconnectionsize "value=" "/>--><property name=" validationQuery "value=" ${ Validationquery} "/><property name=" Testonborrow "value=" false "/><property name=" TestOnReturn "value=" False "/><property name=" Testwhileidle "value=" true "/><!--configuration interval to detect the idle connection that needs to be closed, in milliseconds-->< Property Name= "Timebetweenevictionrunsmillis" value= "60000"/><!--Configure the minimum time for a connection to survive in a poolSeconds--><property name= "Minevictableidletimemillis" value= "25200000"/><!--open removeabandoned function-->< Property Name= "removeabandoned" value= "true"/><!--1800 seconds, which is 30 minutes--><property name= " Removeabandonedtimeout "value=" 1800 "/><!--off abanded connection output error log--><property name=" logabandoned "value=" True "/><!--monitoring database--><!--<property name=" Filters "value=" stat "/>--><property name=" Filters " Value= "Mergestat"/></bean><!--Configure hibernate session factory--><bean id= "Sessionfactory" class= " Org.springframework.orm.hibernate4.LocalSessionFactoryBean "><property name=" DataSource "ref=" DataSource "/ ><property name= "hibernateproperties" ><props><prop key= "Hibernate.hbm2ddl.auto" >${ Hibernate.hbm2ddl.auto}</prop><prop key= "Hibernate.dialect" >${hibernate.dialect}</prop>< Prop key= "Hibernate.show_sql" >${hibernate.show_sql}</prop><prop key= "Hibernate.format_sql" >${ Hibernate.format_sql}</prop></props></property><!--the Hibernate class file configured by automatic scanning annotations--><property name= " Packagestoscan "><list><value>com.dao</value></list></property></bean> <!--configuration transaction manager--><bean name= "TransactionManager" class= " Org.springframework.orm.hibernate4.HibernateTransactionManager "><property name=" sessionfactory "ref=" Sessionfactory "></property></bean><!--annotations Configure things--><tx:annotation-driven Transaction-manager= "TransactionManager"/><!--Interceptor Configuration things--><!--<tx:advice id= "Transactionadvice" Transaction-manager= "TransactionManager" > <tx:attributes> <tx:method name= "add*"/> <tx:method Name= "save*"/> <tx:method name= "update*"/> <tx:method name= "modify*"/> <tx:method name= "edit*"/ > <tx:method name= "delete*"/> <tx:method name= "remove*"/> <tx:method name= "Repair"/> <tx: Method Name= "Deleteandrepair"/> <tx:method name= "get* "propagation=" SUPPORTS "/> <tx:method name=" find* "propagation=" SUPPORTS "/> <tx:method name=" load* " propagation= "SUPPORTS"/> <tx:method name= "search*" propagation= "SUPPORTS"/> <tx:method name= "datagrid*" propagation= "SUPPORTS"/> <tx:method name= "*" propagation= "SUPPORTS"/> </tx:attributes> </tx: advice> <aop:config> <aop:pointcut id= "transactionpointcut" expression= "Execution (* Com.jesus.sshframework.service. *impl.* (..)) " /> <aop:advisor pointcut-ref= "transactionpointcut" advice-ref= "Transactionadvice"/> </aop:config>--   ></beans>

  

Congfig.properties (Hibernate connection Configuration)

#MySQL  hibernate.dialect=org.hibernate.dialect.mysqldialectdriverclassname= Com.mysql.jdbc.drivervalidationquery=select 1jdbc_url=jdbc:mysql://127.0.0.1:3306/test?useunicode=true& characterencoding=utf-8jdbc_username=rootjdbc_password=  hibernate.hbm2ddl.auto=updatehibernate.show_sql= Truehibernate.format_sql=false  sessioninfoname=sessioninfo    uploadfieldname=filedata  uploadfilemaxsize=20971520  uploadfileexts=txt,rar,zip,doc,docx,xls,xlsx,jpg,jpeg,gif,png,swf,wmv,avi,wma, Mp3,mid  uploaddirectory=attached  

  

Spring +spring+ Hibernate configuration 1

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: info-contact@alibabacloud.com 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.