SpringMVC(5.21)+Spring(5.21)+MybatisPlus+Druid+P6spy+Log4j2配置及优化

SpringMVC(5.21)+Spring(5.21)+MybatisPlus+Druid+P6spy+Log4j2配置及优化

SpringMVC-config.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:mvc="http://www.springframework.org/schema/mvc"  xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    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"
>
    <!--注解方式 -->
    <context:component-scan base-package="com.zg.controller" />
    <!-- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  + + + + + + + + + + + + + -->
    <!--注解方式 -->
    <!-- 类型转换器 -->
    <mvc:annotation-driven><!-- conversion-service="myConversionService" -->
        <!-- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  + + + + + + + + + + + + + + + -->
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8
                        </value>
                    </list>
                </property>
            </bean>
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8
                        </value>
                        <value>application/json
                        </value>
                    </list>
                </property>
                <property name="features">
                    <list>
                        <!-- Date的日期转换器 -->
                        <value>WriteDateUseDateFormat
                        </value>
                        <!-- NUll转'' -->
                        <!-- <value>WriteNonStringValueAsString</value>  <value>PrettyFormat</value> <value>UseSingleQuotes</value>
                            <value>WriteNullStringAsEmpty </value> -->
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
    <!-- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  + + + + + + + + + + + + + -->
    <!-- 配置拦截器 -->
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/customer/sys/**" />
            <bean class="com.zg.util.MyInterceptor" />
        </mvc:interceptor>
    </mvc:interceptors>
    <!-- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  + + + + + + + + + + + + + -->
    <!-- 静态资源访问 -->
    <!-- 注意映射地址MApping -->
    <mvc:resources mapping="/statics/**" location="/statics/" />
    <!-- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  + + + + + + + + + + + + + -->
    <!-- 类型转换器 -->
    <bean id="myConversionService"  class="org.springframework.context.support.ConversionServiceFactoryBean">
        <property name="converters">
            <list>
                <bean class="com.zg.util.StringToDateConverter">
                    <constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" />
                </bean>
            </list>
        </property>
    </bean>
    <!-- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  + + + + + + + + + + + + + -->
    <!-- 完成视图的对应 -->
    <!-- 对转向页面的路径解析。prefix:前缀, suffix:后缀 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" > <property  name="prefix" value="/WEB-INF/jsp/"
        /> <property name="suffix" value=".jsp" /> </bean>
    <!-- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  + + + + + + + + + + + + + -->
    <!-- 全局异常处理 -->
    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
            <props>
                <prop key="java.lang.RuntimeException">error</prop>
                <prop key="java.lang.Exception">error</prop>
            </props>
        </property>
    </bean>
    <!-- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  + + + + + + + + + + + + + -->
    <!-- 配置MultipartResolver,用于上传文件,使用spring的CommonsMultipartResolver -->
    <bean id="multipartResolver"  class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="5000000" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>
    <!-- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  + + + + + + + + + + + + + -->
    <!-- html视图解析器 必须先配置freemarkerConfig,注意html是没有prefix前缀属性的 -->
    <bean id="freemarkerConfig"  class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="templateLoaderPath">
            <value>/WEB-INF/html/</value>
        </property>
        <property name="defaultEncoding" value="utf-8"></property>
    </bean>
    <!-- 配置多视图解析器:输出不同路径中的页面 -->
<!--    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="defaultContentType" value="text/html" />
        <property name="mediaTypes">
            <map>
                <entry key="html" value="text/html;charset=UTF-8" />
                <entry key="json" value="application/json;charset=UTF-8" />
                <entry key="xml" value="application/xml;charset=UTF-8" />
            </map>
        </property>
        <property name="viewResolvers">
            <list>
                contentType默认为text/html视图名为任意
                <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                    <property name="prefix" value="/WEB-INF/jsp/" />
                    <property name="suffix" value=".jsp" />
                </bean>
                jsp
                <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                    <property name="viewClass"  value="org.springframework.web.servlet.view.JstlView" />
                    <property name="contentType" value="text/html" />
                    <property name="viewNames" value="*User" />
                    <property name="prefix" value="/user/" />
                    <property name="suffix" value=".jsp" />
                    <property name="order" value="1"></property>
                </bean>
                <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"  p:order="2">
                    <property name="viewClass"  value="org.springframework.web.servlet.view.JstlView" />
                    <property name="contentType" value="text/html" />
                    <property name="viewNames" value="*Product" />
                    <property name="prefix" value="/product/" />
                    <property name="suffix" value=".jsp" />
                </bean>
                json
                <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                    <property name="viewClass"  value="org.springframework.web.servlet.view.JstlView" />
                    <property name="contentType" value="application/json;charset=UTF-8" />
                    <property name="viewNames" value="*Json" />
                    <property name="prefix" value="/json/" />
                    <property name="suffix" value=".jsp" />
                </bean>
                html
                <bean id="htmlviewResolver"  class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
                    <property name="suffix" value=".html" />
                    <property name="order" value="0"></property>
                    <property name="contentType" value="text/html;charset=UTF-8"></property>
                    <property name="viewNames" value="user" />
                </bean>
            </list>
        </property>
    </bean> -->
</beans>
Spring>>>applicationContext.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:aop="http://www.springframework.org/schema/aop"  xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"  xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="   
            http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
            http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop-2.5.xsd   
            http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - -  - - - - -->
    <context:component-scan base-package="com.zg">
        <context:exclude-filter type="annotation"  expression="org.springframework.stereotype.Controller" />
    </context:component-scan>
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - -  - - - - -->
    <bean id="vendorProperties"  class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="properties">
            <props>
                <prop key="Oracle">oracle</prop>
                <prop key="MySQL">mysql</prop>
                <prop key="PostgreSQL">postgresql</prop>
            </props>
        </property>
    </bean>
    <bean id="databaseIdProvider" class="org.apache.ibatis.mapping.VendorDatabaseIdProvider">
        <property name="properties" ref="vendorProperties" />
    </bean>
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - -
        - - - - -->
    <!-- 读取数据库配置文件 -->
    <context:property-placeholder location="classpath:databaseDBCP.properties" />
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - -
        - - - - -->
    <!-- 获取数据源(使用Druid连接池) -->
    <bean id="dataSourceA" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"  scope="singleton">
        <property name="driverClassName" value="${postgresql.driver}" />
        <property name="url" value="${postgresql.url}" />
        <property name="username" value="${postgresql.username}" />
        <property name="password" value="${postgresql.password}" />
        <property name="filters" value="stat" />
        <property name="validationQuery" value="SELECT 1" />
        <!-- 最大并发连接数 -->
        <property name="maxActive" value="30" />
        <!-- 初始化连接数量 -->
        <property name="initialSize" value="5" />
        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="60000" />
        <!-- 最小空闲连接数 -->
        <property name="minIdle" value="10" />
        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="60000" />
        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="300000" />
        <!-- 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测, 如果空闲时间大于timeBetweenEvictionRunsMillis, 执行validationQuery检测连接是否有效。 -->
        <property name="testWhileIdle" value="true" />
        <!-- 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 -->
        <property name="testOnBorrow" value="true" />
        <!-- 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能 -->
        <property name="testOnReturn" value="false" />
        <property name="maxOpenPreparedStatements" value="20" />
        <!-- 打开removeAbandoned功能 -->
        <property name="removeAbandoned" value="true" />
        <!-- 1800秒,也就是30分钟 -->
        <property name="removeAbandonedTimeout" value="1800" />
        <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
    <property name="poolPreparedStatements" value="true" />
    <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
        <!-- 关闭abanded连接时输出错误日志 -->
        <property name="logAbandoned" value="true" />
        <!-- 若需要mybatis的批量sql需配置 不配置则报错:nested exception is java.sql.SQLException:  sql injection violation, multi-statement not allow -->
        <property name="proxyFilters">
            <list>
                <ref bean="wall-filter" />
                <ref bean="stat-filter" />
                <ref bean="log-filter" />
            </list>
        </property>
    </bean>
    <!-- 若需要mybatis的批量sql需配置 -->
    <bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
        <property name="config" ref="wall-config" />
    </bean>
    <bean id="wall-config" class="com.alibaba.druid.wall.WallConfig">
        <property name="multiStatementAllow" value="true" />
    </bean>
    <!--Start 慢SQL记录 数据源配置p:proxyFilters="stat-filter,log-filter" -->
    <bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
        <!-- 慢sql时间设置,即执行时间大于3秒的都是慢sql -->
        <property name="slowSqlMillis" value="3000" />
        <property name="logSlowSql" value="true" />
    </bean>
    <bean id="log-filter" class="com.alibaba.druid.filter.logging.Log4j2Filter">
        <property name="dataSourceLogEnabled" value="true" />
        <property name="statementExecutableSqlLogEnable" value="true" />
    </bean>
<!-- ===================================================================================================================== -->
    <!--end 慢SQL记录 -->
    <!--p6spy连接池的配置,这里采用嵌套运行.内部嵌入DRUID-->
        <bean id="dataSource" class="com.p6spy.engine.spy.P6DataSource">
            <constructor-arg ref="dataSourceA">
        </constructor-arg>
    </bean>
    
    <!-- 配置SqlSessionFactoryBean 采用Mybatis-PLUS的方式注入-->
    <bean id="sqlSessionFactoryA"  class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
        <!-- 引用数据源组件 -->
        <property name="dataSource" ref="dataSource" />
        <!-- 自动扫描mapping.xml文件 多库时最好指定,防止报错 -->
    <!--    <property name="mapperLocations" value="classpath*:com/zg/dao/*.xml"/>  -->
        <!-- 引用MyBatis配置文件中的配置 -->
        <property name="configLocation" value="classpath:mybatis-config.xml" />
         <property name="typeAliasesPackage" value="com.zg.dto"/>
           <property name="databaseIdProvider" ref="databaseIdProvider" />
    </bean>
    <!--3 配置DAO 扫描Mapper接口,自动生成DAO接口的实现类对象,配置SQL映射文件 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.zg.dao" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryA"></property>
    </bean>
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - -
        - - - - -->
    <!-- 定义事务管理器 -->
    <bean id="transactionManager"  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSourceA" />
    </bean>
    <!--启用事务注解方式 -->
    <tx:annotation-driven />
    <!-- 配置事务属性 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="find*" propagation="SUPPORTS" />
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="del*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="*" propagation="REQUIRED" />
        </tx:attributes>
    </tx:advice>
    <!-- 启用AOP注解 -->
    <aop:aspectj-autoproxy />
    <!-- 定义切面AOP管理事务 -->
    <aop:config proxy-target-class="true">
        <aop:pointcut id="serviceMethod" expression="execution(* com.zg.service..*.*(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" />
    </aop:config>
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - -->
    <bean id="druid-stat-interceptor"  class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor">
    </bean>
    <bean id="druid-type-proxyCreator"  class="com.alibaba.druid.support.spring.stat.BeanTypeAutoProxyCreator">
        <property name="targetBeanType" value="com.zg.dao.CustomerDAO" />
        <property name="interceptorNames">
            <list>
                <value>druid-stat-interceptor</value>
            </list>
        </property>
    </bean>
</beans>
Mybatis-PLus.config.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>
    <!-- MyBatis设置 -->
    <settings>
        <!-- 使用jdbc的getGeneratedKeys获取数据库自增主键值 -->
        <setting name="useGeneratedKeys" value="true" />
        <!-- 使用列别名替换列名 默认:true -->
        <setting name="useColumnLabel" value="true" />
        <!-- 开启驼峰命名转换:Table{create_time} -> Entity{createTime} -->
        <setting name="mapUnderscoreToCamelCase" value="true" />
        <setting name="cacheEnabled" value="true" />
        <setting name="lazyLoadingEnabled" value="false" />
        <setting name="aggressiveLazyLoading" value="false" />
        <setting name="logImpl" value="STDOUT_LOGGING" />
    </settings>
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - -->
    <!--类型别名 -->
    <typeAliases>
        <package name="com.zg.dto" />
    </typeAliases>
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - -->
    <!-- 添加MyBatis对PageHalper的插件支持,其实就是拦截器,每次执行SQL的时候,都会被拦截下来做一些处理  -->
    <plugins>
        <!--     com.github.pagehelper为PageHelper类所在包名, 
        5.0用com.github.pagehelper.PageInterceptor, 
        4.0低版本用的com.github.pagehelper.PageHelper,
            否则报错 -->
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
           <!--  4.0.0以后版本可以不设置该参数 ,可以自动识别 -->
         <!--    <property name="dialect" value="postgresql"/> -->
           <!--  该参数默认为false 设置为true时,会将RowBounds第一个参数offset当成pageNum页码使用 和startPage中的pageNum效果一样 -->
            <property name="offsetAsPageNum" value="true" />
        <!--     该参数默认为false 设置为true时,使用RowBounds分页会进行count查询 -->
            <property name="rowBoundsWithCount" value="true" />
           <!--  设置为true时,如果pageSize=0或者RowBounds.limit = 0 
            就会查询出全部的结果 (相当于没有执行分页查询,但是返回结果仍然是Page类型) -->
            <property name="pageSizeZero" value="true" />
           <!--  3.3.0版本可用 - 分页参数合理化,默认false禁用 启用合理化时, 如果pageNum<1会查询第一页, 
            如果pageNum>pages会查询最后一页 禁用合理化时,如果pageNum<1或pageNum>pages会返回空数据 -->
            <property name="reasonable" value="true" />
           <!--  3.5.0版本可用 - 为了支持startPage(Object params)方法 增加了一个`params`参数来配置参数映射,
            用于从Map或ServletRequest中取值 可以配置pageNum,pageSize,count,pageSizeZero,reasonable,orderBy,
                不配置映射的用默认值 不理解该含义的前提下,不要随便复制该配置 -->
            <property name="params" value="pageNum=start;pageSize=limit;" />
           <!--  支持通过Mapper接口参数来传递分页参数 -->
            <property name="supportMethodsArguments" value="true" />
           <!--  always总是返回PageInfo类型,check检查返回类型是否为PageInfo,none返回Page -->
            <property name="returnPageInfo" value="check" />
        </plugin>
    </plugins>
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - -->
    <!-- databaseid -->
    <databaseIdProvider type="com.zg.util.MyDatabaseIdProvider" />
</configuration>
WEB.XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee  http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID"
    version="4.0"
>
    <display-name>rebluid_ssm</display-name>
 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - -->
    <!--start 数据库性能监控 p:filters="stat -->
    <!--spring中配置数据源 p:filters="stat,wall,log4j" stat和wall。一个是用于监控,一个是用于防火墙。如果想使用sql防火墙,必须加上wall -->
    <servlet>
        <servlet-name>DruidStatView</servlet-name>
        <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
        <!--<init-param> -->
        <!--白名单 -->
        <!--<param-name>allow</param-name> -->
        <!--如果是限定指定的子网里的所有ip都可以访问,那就是ip/子网掩码数。例如 192.168.1.120/24 就相当于192.168.1.* -->
        <!--<param-value>192.168.1.120/24,127.0.0.1</param-value> -->
        <!--</init-param> -->
        <init-param>
            <!-- 用户名 -->
            <param-name>loginUsername</param-name>
            <param-value>root</param-value>
        </init-param>
        <init-param>
            <!-- 密码 -->
            <param-name>loginPassword</param-name>
            <param-value>root</param-value>
        </init-param>
        <!-- 重置记录 -->
        <init-param>
            <param-name>resetEnable</param-name>
            <param-value>false</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>DruidStatView</servlet-name>
        <url-pattern>/druid/*</url-pattern>
    </servlet-mapping>
    <filter>
        <!-- 用于采集web-jdbc关联监控的数据 -->
        <filter-name>DruidWebStatFilter</filter-name>
        <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
        <init-param>
            <!-- 排除不需要监控的url -->
            <param-name>exclusions</param-name>
            <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>
        </init-param>
        <init-param>
            <!-- 缺省sessionStatMaxCount是1000个 -->
            <param-name>sessionStatMaxCount</param-name>
            <param-value>1000</param-value>
        </init-param>
        <init-param>
            <!--开启session统计功能 -->
            <param-name>sessionStatEnable</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <!--配置principalSessionName,使得druid能够知道当前的session的用户是谁 -->
            <param-name>principalSessionName</param-name>
            <param-value>session_user_key</param-value>
        </init-param>
        <init-param>
            <!--配置profileEnable能够监控单个url调用的sql列表 -->
            <param-name>profileEnable</param-name>
            <param-value>false</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>DruidWebStatFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!--end 数据库性能监控 -->
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - -->
    <!-- 总控制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:springmvc-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <!-- WEB上下文连接器 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext-*.xml</param-value>
    </context-param>
    <!-- 过滤器的配置 -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <!--统一字符集 -->
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <!-- 强制Encoding统一字符编码 -->
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <!-- 过滤器映射 /*对全部路径进行拦截过滤 -->
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - -->
<!-- log4j2-begin -->
     <listener>
          <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
    </listener>
     <filter>
         <filter-name>log4jServletFilter</filter-name>
         <filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
     </filter>
     <filter-mapping>
         <filter-name>log4jServletFilter</filter-name>
         <url-pattern>/*</url-pattern>
         <dispatcher>REQUEST</dispatcher>
         <dispatcher>FORWARD</dispatcher>
         <dispatcher>INCLUDE</dispatcher>
         <dispatcher>ERROR</dispatcher>
     </filter-mapping>
     <!-- log4j2-end -->
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - -->
    <!-- 监听器2 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>
LOG4J2
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="off" monitorInterval="1800">
    <properties>
        <property name="FILE_NAME">ubs</property>
    </properties>
    <Appenders>
        <Console name="Console,spy6p" target="SYSTEM_OUT">
            <ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="DENY" />
            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n" />
        </Console>
        <File name="info" fileName="${web:rootDir}/../../ubslogs/info.log" append="true">
            <Filters>
                <ThresholdFilter level="WARN" onMatch="DENY" onMismatch="NEUTRAL" />
                <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY" />
            </Filters>
            <PatternLayout pattern="%d{yyyy.MM.dd HH:mm:ss z} %-5level %class{36} %L %M -  %msg%xEx%n" />
        </File>
        <File name="error" fileName="${web:rootDir}/../../ubslogs/error.log" append="true">
            <Filters>
                <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY" />
            </Filters>
            <PatternLayout pattern="%d{yyyy.MM.dd HH:mm:ss z} %-5level %class{36} %L %M -  %msg%xEx%n" />
        </File>
    </Appenders>
    <Loggers>
        <Root level="trace" additivity="false">
            <!-- 这里是输入到控制台-->
            <AppenderRef ref="Console"/>
            <!-- 这里是输入到文件,很重要-->
            <AppenderRef ref="info"/>
            <AppenderRef ref="error"/>
        </Root>
    </Loggers>
</Configuration>
database.properties
postgresql.driver=org.postgresql.Driver
postgresql.url=jdbc:postgresql\://localhost\:5432/kk
postgresql.username=postgres
postgresql.password=root
#最小空闲数
minIdle=45
#允许最大空闲数  不能配置太小
maxIdle=50
#初始化时 连接个数   默认是0
initialSize=5   
#同时连接的最大活动数   默认是8
maxActive=100
#最大等待时间
maxWait=100
#超过这个时间就会将没用的连接回收秒为单位
removeAbandonedTimeout=180
#是否开启无用连接的回收机制
#【当前空闲连接数<2 && 当前活动数>最大活动数-3】这种情况下会回收
removeAbandoned=true
#dataSourceA=java:comp/env/jdbc/data
#-----------------------------------------------------
mysql8.url=jdbc:mysql://127.0.0.1:3306/customer?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8
mysql8.username = root
mysql8.password= root
mysql8.driver= com.mysql.cj.jdbc.Driver
#最小空闲数
minIdle=45
#允许最大空闲数  不能配置太小
maxIdle=50
#初始化时 连接个数   默认是0
initialSize=5   
#同时连接的最大活动数   默认是8
maxActive=100
#最大等待时间
maxWait=100
#超过这个时间就会将没用的连接回收秒为单位
removeAbandonedTimeout=180
#是否开启无用连接的回收机制
#【当前空闲连接数<2 && 当前活动数>最大活动数-3】这种情况下会回收
removeAbandoned=true
spy.propertiles
 
modulelist=com.p6spy.engine.spy.P6SpyFactory,com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory
 
driverlist=org.postgresql.Driver
 
stacktraceclass=true
 
logMessageFormat=com.p6spy.engine.spy.appender.MultiLineFormat
 
databaseDialectDateFormat=yyyy-MM-dd'T'HH:mm:ss.SSSZ
 
filter=true
 
excludecategories=info,debug,result,resultset
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值