spring+springmvc+mybatis配置文件

2020-12-13 06:25

阅读:290

标签:sse   style   cep   scanner   一起   put   int   action   clear   

最近在学习SSM,自己上手了一个crm项目,这两天对底层配置文件做了个总结。

sqlmapconfig.xml

xml version="1.0" encoding="UTF-8" ?>
DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
configuration>
    
    
    
    
    typeAliases>
        
        package name="cn.itcast.ssm.po"/>
    typeAliases>

    

    
configuration>

applicationContext.xml

把spring-mybatis.xml文件和spring-service.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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
    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/context
                           http://www.springframework.org/schema/context/spring-context.xsd
                           http://www.springframework.org/schema/mvc
                           http://www.springframework.org/schema/mvc/spring-mvc.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx.xsd
                           http://www.springframework.org/schema/aop 
                           http://www.springframework.org/schema/aop/spring-aop.xsd ">
    
    bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource"
        destroy-method="close" init-method="init">
        property name="defaultAutoCommit" value="true" />
        
        
        property name="maxActive" value="500" />
        property name="initialSize" value="5" />
        property name="maxWait" value="240000" />
        property name="minIdle" value="5" />
        property name="timeBetweenEvictionRunsMillis" value="3000" />
        property name="timeBetweenLogStatsMillis" value="0" />
        property name="minEvictableIdleTimeMillis" value="300000" />
        property name="validationQuery" value="SELECT 1" />
        property name="testWhileIdle" value="true" />
        property name="testOnBorrow" value="false" />
        property name="testOnReturn" value="false" />
        
        property name="poolPreparedStatements" value="false" />
        property name="maxPoolPreparedStatementPerConnectionSize"
            value="100" />
        property name="removeAbandoned" value="true" />
        property name="removeAbandonedTimeout" value="60" />
        property name="logAbandoned" value="false" />
        property name="connectionProperties"
            value="druid.stat.slowSqlMillis=50;druid.stat.loggerName=log4j;" />
        property name="driverClassName" value="${dbdriver}" />
        property name="url" value="${dburl}" />
        property name="username" value="${dbuser}" />
        property name="password" value="${dbpwd}" />
        
        
        property name="proxyFilters">
            list>
                ref bean="logfilter" />
                ref bean="statFilter" />
                
                ref bean="wallFilter" />
            list>
        property>
        
        
    bean>

    bean id="statFilter" class="com.alibaba.druid.filter.stat.StatFilter">
        property name="mergeSql" value="true" />
    bean>

    bean id="wallFilter" class="com.alibaba.druid.wall.WallFilter">
        property name="dbType" value="sqlserver" />
        property name="logViolation" value="true" />
        property name="throwException" value="true" />
        property name="config" ref="wall-filter-config" />
    bean>
    
    bean id="wall-filter-config" class="com.alibaba.druid.wall.WallConfig"
        init-method="init">
        property name="dir" value="classpath:config/druid/wall/sqlserver" />
        property name="multiStatementAllow" value="true"/>
        property name="noneBaseStatementAllow" value="false"/>
        property name="commentAllow" value="true"/>
        property name="mustParameterized" value="false"/>
        property name="strictSyntaxCheck" value="true"/>
    bean>

    bean id="logfilter" class="com.alibaba.druid.filter.logging.Slf4jLogFilter">
        property name="connectionConnectBeforeLogEnabled" value="false">property>
        property name="connectionConnectAfterLogEnabled" value="false">property>
        property name="connectionCommitAfterLogEnabled" value="false">property>
        property name="connectionRollbackAfterLogEnabled" value="false">property>
        property name="connectionCloseAfterLogEnabled" value="false">property>

        property name="statementCreateAfterLogEnabled" value="false">property>
        property name="statementPrepareAfterLogEnabled" value="false">property>
        property name="statementPrepareCallAfterLogEnabled" value="false">property>

        property name="statementExecuteAfterLogEnabled" value="false">property>
        property name="statementExecuteQueryAfterLogEnabled" value="false">property>
        property name="statementExecuteUpdateAfterLogEnabled" value="false">property>
        property name="statementExecuteBatchAfterLogEnabled" value="false">property>
        property name="statementExecutableSqlLogEnable" value="false">property>

        property name="statementCloseAfterLogEnabled" value="false">property>
        property name="statementParameterSetLogEnabled" value="false">property>
        property name="statementParameterClearLogEnable" value="false">property>

        property name="resultSetNextAfterLogEnabled" value="false">property>
        property name="resultSetOpenAfterLogEnabled" value="false">property>
        property name="resultSetCloseAfterLogEnabled" value="false">property>

        property name="resultSetLogEnabled" value="false">property>
        property name="resultSetLogErrorEnabled" value="false">property>

        property name="dataSourceLogEnabled" value="true">property>
        property name="connectionLogEnabled" value="true">property>
        property name="connectionLogErrorEnabled" value="true">property>
        property name="statementLogEnabled" value="true">property>
        property name="statementLogErrorEnabled" value="true">property>
    bean>

    
    bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        property name="dataSource" ref="druidDataSource" />
        
        property name="configLocation"
            value="classpath:cn/com/dl/core/dao/sqlmapconfig.xml" />
        
        property name="mapperLocations" value="classpath:cn/com/dl/core/dao/**/mapper/*Mapper.xml" />
    bean>
    
    bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        property name="dataSource" ref="druidDataSource" />
    bean>

    
    
    
    bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        property name="basePackage" value="cn.com.dl.core.dao" />
        property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    bean>

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

    tx:advice id="txAdvice" transaction-manager="transactionManager">
        tx:attributes>
            
            tx:method name="*insert*" isolation="DEFAULT" propagation="REQUIRED" />
            tx:method name="*update*" isolation="DEFAULT" propagation="REQUIRED" />
        tx:attributes>
    tx:advice>

    aop:config>
        
        aop:pointcut expression="execution(* cn.com.dl.core.service.*.*.*(..))" id="point" />
        aop:advisor advice-ref="txAdvice" pointcut-ref="point" />
    aop:config>
beans>
 

springmvc.xml(spring-servlet.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:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util-4.2.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">
    
  
    
    
    context:component-scan base-package="cn.com.dl.web.controller" />
    mvc:annotation-driven/>

    
    bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        property name="messageConverters">
            list>
                ref bean="textJsonHttpMessageConverter" />
            list>
        property>
    bean>
    
    bean id="textJsonHttpMessageConverter"
        class="cn.com.dl.external.converter.json.MappingJackson2HttpMessageConverter">
        property name="objectMapper">
            bean class="com.fasterxml.jackson.databind.ObjectMapper">
                property name="dateFormat">
                    bean class="java.text.SimpleDateFormat">
                        constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" />
                    bean>
                property>
                
                property name="serializationInclusion">
                    util:constant static-field="com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL"/>
                property>
            bean>
        property>
        property name="supportedMediaTypes">
            list>
                value>text/jsonvalue>  
            list>
        property>
    bean>

    
    bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/" p:suffix=".jsp" />

    mvc:resources mapping="/template/**" location="/template/" />
    mvc:resources mapping="/js/**" location="/js/" />
    mvc:resources mapping="/styles/**" location="/styles/" />
    mvc:resources mapping="/image/**" location="/image/" />
    
beans> 

web.xml

xml version="1.0" encoding="UTF-8"?>
web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    display-name>springmvc_mybatisdisplay-name>


    context-param>
        param-name>contextConfigLocationparam-name>
        param-value>/WEB-INF/classes/spring/applicationContext.xmlparam-value>
    context-param>
    listener>
        listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
    listener>


    
    servlet>
        servlet-name>springmvcservlet-name>
        servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
        
        init-param>
            param-name>contextConfigLocationparam-name>
            param-value>classpath:spring/springmvc.xmlparam-value>
        init-param>
    servlet>

    servlet-mapping>
        servlet-name>springmvcservlet-name>
        
        url-pattern>*.actionurl-pattern>
    servlet-mapping>
    
    welcome-file-list>
        welcome-file>index.htmlwelcome-file>
        welcome-file>index.htmwelcome-file>
        welcome-file>index.jspwelcome-file>
        welcome-file>default.htmlwelcome-file>
        welcome-file>default.htmwelcome-file>
        welcome-file>default.jspwelcome-file>
    welcome-file-list>

log4j.properties文件

# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration...
log4j.logger.com.ma.core=DEBUG
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

 db.properties文件

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test
jdbc.username=root
jdbc.password=

spring+springmvc+mybatis配置文件

标签:sse   style   cep   scanner   一起   put   int   action   clear   

原文地址:https://www.cnblogs.com/SI0301/p/11178711.html


评论


亲,登录后才可以留言!