SPRINGMVC (v) Integrated Ali Druid database connection pooling and transaction configuration, integrated mybatis__ database

Source: Internet
Author: User
Tags aop config connection pooling file upload json rollback xmlns root directory

Thanks to our small leader, he is in the study, we in the use, he has gone after no perfect, has been used so far. If you look at the friends here have what needs to integrate in, the generous enlighten, thank you.

<?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:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
xmlns:context= "Http://www.springframework.org/schema/context"
Xmlns:mvc= "Http://www.springframework.org/schema/mvc"
xmlns:tx= "Http://www.springframework.org/schema/tx"
Xsi:schemalocation= "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans.xsd
Http://www.springframework.org/schema/aop
Http://www.springframework.org/schema/aop/spring-aop.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-4.0.xsd
Http://www.springframework.org/schema/mvc
Http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
Http://www.springframework.org/schema/tx
Http://www.springframework.org/schema/tx/spring-tx.xsd
">
<!--The following configuration, if Include-filter type=annotation is configured, only the annotations that are configured in it will be scanned, provided that
<context:component-scan base-package= "Com.net" ></context:component-scan>
<bean
class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix" value= "/web-inf/pages/" ></property>
<property name= "suffix" value= "" ></property>
</bean>
<!--the produces in the @RequestMapping will work only if the following label is configured, which is related to its registered message body conversion class.
<mvc:annotation-driven>
<mvc:message-converters register-defaults= "true" >
<bean
class= "Com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter" >
<property name= "Supportedmediatypes" value= "Application/json"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<mvc:default-servlet-handler/>
<!--the contents of the location can be written in multiple addresses, such as can be written location= "/,/**" before the root directory to find and
<mvc:resources mapping= "/upload/**" location= "/upload/,/ckeditoruploadimage/"/>
<mvc:resources mapping= "/images/**" location= "/web-inf/images/"/>
<mvc:resources mapping= "/css/**" location= "/web-inf/css/"/>
<mvc:resources mapping= "/plugins/**" location= "/web-inf/plugins/"/>
<mvc:resources mapping= "/js/**" location= "/web-inf/js/"/>
<mvc:resources mapping= "/*.html" location= "/web-inf/static_pages/"/>
<mvc:resources mapping= "/*.xml" location= "/web-inf/"/>
<mvc:interceptors>
<bean class= "Com.net.intercpter.MyInterceptor" ></bean>
</mvc:interceptors>

<bean name= "TransactionManager" class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name= "DataSource" ref= "DataSource" ></property>
</bean>
<!--99 frame assignment is problematic, the Web request can inject the value of the property file, the code test cannot be injected, causing the JUnit test DAO beginning to load the configuration file error-
<bean id= "Propertyconfigurer"
class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name= "Locations" >
<list>
<value>classpath:dbconfig.properties</value>
</list>
</property>
</bean>
<!--Ali Druid database connection pool--
<bean id= "DataSource" class= "Com.alibaba.druid.pool.DruidDataSource"
destroy-method= "Close" >
<!--database basic information Configuration--
<property name= "url" value= "${url}"/>
<property name= "username" value= "${username}"/>
<property name= "Password" value= "${password}"/>
<property name= "Driverclassname" value= "${driverclassname}"/>
<property name= "Filters" value= "${filters}"/>
<!--the maximum number of concurrent connections--
<property name= "maxactive" value= "${maxactive}"/>
<!--initialize the number of connections--
<property name= "InitialSize" value= "${initialsize}"/>
<!--configuration Gets the time that the connection waits timeout--
<property name= "maxwait" value= "${maxwait}"/>
< minimum number of idle connections!--
<property name= "Minidle" value= "${minidle}"/>
< how long!--configuration interval to detect idle connections that need to be closed, in milliseconds-and
<property name= "Timebetweenevictionrunsmillis" value= "${timebetweenevictionrunsmillis}"/>
<!--Configure the minimum time for a connection to survive in a pool, in milliseconds--
<property name= "Minevictableidletimemillis" value= "${minevictableidletimemillis}"/>
<property name= "Validationquery" value= "${validationquery}"/>
<property name= "Testwhileidle" value= "${testwhileidle}"/>
<property name= "Testonborrow" value= "${testonborrow}"/>
<property name= "Testonreturn" value= "${testonreturn}"/>
<property name= "maxopenpreparedstatements" value= "${maxopenpreparedstatements}"/>
<!--open removeabandoned function--
<property name= "removeabandoned" value= "${removeabandoned}"/>
<!--1800 seconds, that's 30 minutes--
<property name= "Removeabandonedtimeout" value= "${removeabandonedtimeout}"/>
< output error log!--close abanded connection--
<property name= "logabandoned" value= "${logabandoned}"/>
</bean>

<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >
<tx:attributes>
<tx:method name= "delete*" propagation= "REQUIRED" read-only= "false"
Rollback-for= "Java.lang.Exception"/>
<tx:method name= "insert*" propagation= "REQUIRED" read-only= "false"
Rollback-for= "Java.lang.Exception"/>
<tx:method name= "update*" propagation= "REQUIRED" read-only= "false"
Rollback-for= "Java.lang.Exception"/>
<tx:method name= "save*" propagation= "REQUIRED" read-only= "false"
Rollback-for= "Java.lang.Exception"/>
</tx:attributes>
</tx:advice>

<aop:aspectj-autoproxy proxy-target-class= "true"/>

<!--things handled--
<aop:config>
<aop:pointcut id= "PC" expression= "Execution (* com.net.crud.service.. *(..))" /> <!--directory structure, class annotations under this directory: @Service ("Xxxservice")--
<aop:advisor pointcut-ref= "PC" advice-ref= "Txadvice"/>
</aop:config>

<!--mybatis Configuration--
<bean id= "Sqlsessionfactory" class= "Org.mybatis.spring.SqlSessionFactoryBean" >
<property name= "DataSource" ref= "DataSource"/>
<property name= "configlocation" value= "Classpath:mybatis/mybatis-config.xml" ></property>
<!--mapper Scan--
<property name= "mapperlocations" value= "Classpath:mybatis/*/*.xml" ></property>
</bean>

<bean id= "Sqlsessiontemplate" class= "Org.mybatis.spring.SqlSessionTemplate" >
<constructor-arg ref= "Sqlsessionfactory"/>
</bean>

<!--custom upload interception, such as maximum upload value and minimum upload value for single file 4M, resolving problems with original file upload and spring upload request being parsed--
<!--HTTP requests with Excludeurls in the URL will not be parsed by Multipartresolver first-
<bean id= "Multipartresolver" class= "Com.net.resolver.MyMultipartResolver" >
<property name= "Excludeurls" >
<list>
<value>ckupload</value>
<value>UEditorConfig</value>
<!--
File upload is implemented using SPRINGMVC, all of which do not need to convert the request temporarily.
Doubt is not known Baidu Editor jar in the file upload code, because see
A jar package is required for file upload and does not get the file format name configured in Config.json
-
<!--<value>UEditorUploadImage</value>-->
</list>
</property>
<!--Specifies that the total size of the uploaded file cannot exceed 16MB. Note that the limit for the Maxuploadsize property is not for individual files, but for the sum of the capacity of all files.
<property name= "Maxuploadsize" >
<value>647772160</value>
</property>
<property name= "Maxinmemorysize" >
<value>4096</value>
</property>
<property name= "Defaultencoding" >
<value>utf-8</value>
</property>
</bean>

</beans>


File structure:


MyBatis Configuration

<?xml version= "1.0" encoding= "UTF-8"?
<! DOCTYPE configuration Public "-//mybatis.org//dtd SQL Map Config 3.0//en"  
     "http:// MYBATIS.ORG/DTD/MYBATIS-3-CONFIG.DTD,
<configuration>

    <!--Configure aliases for entity classes, The type returned in the corresponding mapper.xml of the entity class can write the class name without requiring a full class name of-->
    <typealiases>
         <package name= "Com.net.crud.modal"/>
    </typealiases>
</ Configuration>

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.