zoukankan      html  css  js  c++  java
  • SSM三大配置文件

    1、web.xml

     
    <?xml version="1.0" encoding="UTF-8"?>
    <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">
    <context-param>
        <param-name>ssm-logistics</param-name>
        <param-value>ssm-logistics.root</param-value>
    </context-param>
     <!-- 配置 Spring -->  
        <context-param>  
            <param-name>contextConfigLocation</param-name>  
            <param-value>classpath:conf/spring.xml;classpath:conf/spring-mybatis.xml</param-value>  
        </context-param>
        <!-- 日志记录 -->
        <context-param>
            <!-- 日志配置文件路径 -->
            <param-name>log4jConfigLocation</param-name>
            <param-value>classpath:conf/log4j.properties</param-value>
        </context-param>
        <context-param>
            <!-- 日志页面的刷新间隔 -->
            <param-name>log4jRefreshInterval</param-name>
            <param-value>6000</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
        </listener> 
        
        <listener>  
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
        </listener>  
        <!-- 防止Spring内存溢出监听器 -->  
        <listener>  
            <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>  
        </listener>  
      
          
        <!-- springMVC核心配置 -->
        <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:conf/spring-mvc.xml</param-value>
            </init-param>
            <load-on-startup>2</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>springMVC</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
     
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
     
        <!-- 错误跳转页面 -->
        <error-page>
            <!-- 路径不正确 -->
            <error-code>404</error-code>
            <location>/WEB-INF/errorpage/404.jsp</location>
        </error-page>
        <error-page>
            <!-- 没有访问权限,访问被禁止 -->
            <error-code>405</error-code>
            <location>/WEB-INF/errorpage/405.jsp</location>
        </error-page>
        <error-page>
            <!-- 内部错误 -->
            <error-code>500</error-code>
            <location>/WEB-INF/errorpage/500.jsp</location>
        </error-page>  
          
        <!-- 字符集过滤器 -->  
        <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>  
            <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>
    </web-app>

    2、springMVC.xml

     

     

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:p="http://www.springframework.org/schema/p"
      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-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
        
       <mvc:annotation-driven/>
         <!-- 扫描controller(controller层注入) -->
        <context:component-scan base-package="com.springmvc.ssm.controller"/>
       <!-- 非注解的bean声明注入 -->
       <!--    <bean name="/testController" class="com.springmvc.ssm.controller.TestController"/>  -->
       <!-- 非注解处理器映射器 -->
       <!-- <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/> -->
       <!-- 非注解处理器适配器 -->
       <!-- <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/> -->
       <!-- 注解映射器 -->  
        <!-- <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>   -->
        <!-- 注解适配器   -->
        <!-- <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/> -->
       <!-- 避免IE在ajax请求时,返回json出现下载 -->
       <bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">        
            <property name="supportedMediaTypes">
                <list>
                    <value>text/html;charset=UTF-8</value>
                </list>
            </property>
        </bean>
        
       <!-- 对模型视图添加前后缀 -->
         <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
    </beans>

    3、applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
        xmlns:cache="http://www.springframework.org/schema/cache"
        xsi:schemaLocation="
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/jdbc
        http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
        http://www.springframework.org/schema/cache
        http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util.xsd">
     
        <<span style="color:#ff0000;">!-- 自动扫描web包 ,将带有注解的类 纳入spring容器管理 --></span>
        <context:component-scan base-package="com.eduoinfo.finances.bank.web"></context:component-scan>
     
        <!-- 引入jdbc配置文件 -->
        <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath*:jdbc.properties</value>
                </list>
            </property>
        </bean>
     
        <!-- dataSource 配置 -->
        <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
            <!-- 基本属性 url、user、password -->
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
     
            <!-- 配置初始化大小、最小、最大 -->
            <property name="initialSize" value="1" />
            <property name="minIdle" value="1" />
            <property name="maxActive" value="20" />
     
            <!-- 配置获取连接等待超时的时间 -->
            <property name="maxWait" value="60000" />
     
            <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
            <property name="timeBetweenEvictionRunsMillis" value="60000" />
     
            <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
            <property name="minEvictableIdleTimeMillis" value="300000" />
     
            <property name="validationQuery" value="SELECT 'x'" />
            <property name="testWhileIdle" value="true" />
            <property name="testOnBorrow" value="false" />
            <property name="testOnReturn" value="false" />
     
            <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
            <property name="poolPreparedStatements" value="false" />
            <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
     
            <!-- 配置监控统计拦截的filters -->
            <property name="filters" value="stat" />
        </bean>
     
        <!-- mybatis文件配置,扫描所有mapper文件 -->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" p:dataSource-ref="dataSource" p:configLocation="classpath:mybatis-config.xml" p:mapperLocations="classpath:com/eduoinfo/finances/bank/web/dao/*.xml" />
     
        <span style="color:#ff0000;"><!-- spring与mybatis整合配置,扫描所有dao --></span>
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" p:basePackage="com.eduoinfo.finances.bank.web.dao" p:sqlSessionFactoryBeanName="sqlSessionFactory" />
     
        <!-- 对dataSource 数据源进行事务管理 -->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource" />
     
        <span style="color:#ff0000;"><!-- 配置使Spring采用CGLIB代理 --></span>
        <aop:aspectj-autoproxy proxy-target-class="true" />
     
       <span style="color:#ff0000;"> <!-- 启用对事务注解的支持 --></span>
        <tx:annotation-driven transaction-manager="transactionManager" />
     
    <span style="color:#ff0000;">    <!-- Cache配置 --></span>
        <cache:annotation-driven cache-manager="cacheManager" />
        <bean id="ehCacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="classpath:ehcache.xml" />
        <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="ehCacheManagerFactory" />
     
    </beans>
  • 相关阅读:
    记一次Redis+Getshell经验分享
    冰蝎动态二进制加密WebShell基于流量侧检测方案
    ubuntu16下安装mongodb 3.6
    centos安装sass环境必看
    CLR 调试体系结构
    CLR 调试概述
    CLR Exception---E0434352
    关于System.MissingMethodException异常
    关于异常System.ArgumentException
    从.NET/CLR返回的hresult:0x8013XXXX的解释
  • 原文地址:https://www.cnblogs.com/wenwenzuiniucha/p/14956540.html
Copyright © 2011-2022 走看看