SSM配置文件整合(Spring-SpringMVC-MyBatis)

mybatis-config.xml




<configuration>

configuration>

jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver



jdbc.url=jdbc:mysql://localhost:3306/person?useOldAliasMetadataBehavior=true&autoReconnect=true&
failOverReadOnly=false&characterEncoding=utf-8
jdbc.username=admin
jdbc.password=admin

spring-mybatis.xml


<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-4.2.xsd
         http://www.springframework.org/schema/tx
         http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
         http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
         http://www.springframework.org/schema/mvc
         http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">


<context:component-scan base-package="com.wescr.service.*" />


<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
        <value>classpath:jdbc.propertiesvalue>
        <value>classpath:project.propertiesvalue>
        list> 
    property>
bean>


<bean id="dataSource" 
    class="com.alibaba.druid.pool.DruidDataSource"  destroy-method="close"  init-method="init">
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="filters" value="config" />           
        
      
        <property name="initialSize" value="1" />  
        <property name="minIdle" value="1" />   
        <property name="maxActive" value="20" />  
        <property name="validationQuery" value="SELECT 'x'" />
    <property name="testWhileIdle" value="true" />
    <property name="testOnBorrow" value="false" />
    <property name="testOnReturn" value="false" />   

          
        <property name="maxWait" value="60000" />  
          
        <property name="timeBetweenEvictionRunsMillis" value="60000" />  
          
        <property name="minEvictableIdleTimeMillis" value="300000" />  
        <property name="proxyFilters">
            <list> <ref bean="stat-filter" />   list>
        property>
bean>

<bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
    <property name="slowSqlMillis" value="10000" />
    <property name="logSlowSql" value="true" />
bean>


<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    
    <property name="mapperLocations" value="classpath:com/wescr/mybatis/mapper/*.xml"/>
    <property name="configLocation" value="classpath:mybatis-config.xml">property>
bean>


<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 
    <property name="basePackage" value="com.wescr.mybatis.dao" /> 
bean>


<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource" ref="datasource">property>
bean>



<tx:advice id="txAdvice" transaction-manager="transactionManager">
    
    <tx:attributes>
        
        <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
        
        <tx:method name="get*" read-only="true"/>
    tx:attributes>
tx:advice>


<aop:config>
    
    <aop:pointcut expression="execution (* com.wescr.service.impl.*.*(..))" id="services"/>
    
    <aop:advisor advice-ref="txAdvice" pointcut-ref="services"/>
aop:config>

beans>

springMVC-servlet.xml

 
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.2.xsd
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd ">


<context:component-scan base-package="com.wescr.controller.*" />



<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/views/">property>
    <property name="suffix" value=".jsp">property>
bean>


<bean id="multipartResolver" 
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 
         
        <property name="maxUploadSize" value="52428800"/>
        
        <property name="maxInMemorySize" value="2048"/>        
        <property name="defaultEncoding" value="utf-8" />   
bean> 

 
 
<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> 
    <property name="exceptionMappings"> 
        <props> 
             
            <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">errorprop> 
        props> 
    property> 
bean>
beans>

web.xml


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://java.sun.com/xml/ns/javaee" 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">


<display-name>com-hurongclub-credit-apidisplay-name>


<welcome-file-list>
    <welcome-file>index.jspwelcome-file>
welcome-file-list>

  
<listener>  
    <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>  
listener>  

<listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListenerlistener-class>
listener>

  
<context-param>  
    <param-name>contextConfigLocationparam-name>  
    <param-value>classpath:spring-mybatis.xml  param-value>  
context-param> 


<servlet>
    <servlet-name>springmvcservlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
    <init-param>
        <param-name>contextConfigLocationparam-name>
        <param-value>classpath:springmvc-servlet.xmlparam-value>
    init-param>
    <load-on-startup>1load-on-startup>
    <async-supported>trueasync-supported>
servlet>


<filter>
    <filter-name>encodingFilterfilter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
    <init-param>
        <param-name>encodingparam-name>
        <param-value>UTF-8param-value>
    init-param>
filter>
<filter-mapping>
    <filter-name>encodingFilterfilter-name>
    <url-pattern>/*url-pattern>
filter-mapping>

<servlet-mapping>
    <servlet-name>springmvcservlet-name>
    <url-pattern>/url-pattern>
servlet-mapping>


<servlet>
     <servlet-name>DruidStatViewservlet-name>
     <servlet-class>com.alibaba.druid.support.http.StatViewServletservlet-class>
 servlet>
 <servlet-mapping>
     <servlet-name>DruidStatViewservlet-name>
     <url-pattern>/druid/*url-pattern>
 servlet-mapping>


<error-page>  
        <error-code>404error-code>  
        <location>/error404.jsplocation>  
error-page>   
web-app>

你可能感兴趣的:(SSM配置文件整合(Spring-SpringMVC-MyBatis))