ssm关于配置文件

ssm关于配置文件
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"
         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>Archetype Created Web Application</display-name>

    <!-- 配置过滤器,解决post的乱码问题 -->
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <!-- 其中encoding用来设置编码格式,
        forceEncoding用来设置是否理会 request.getCharacterEncoding()方法,设置为true则强制覆盖之前的编码格式。 -->
        <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>characterEncodingFilter</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    
    
    
    <!-- Restful风格 被该过滤器过滤后会用post方法提交,form表单需设为enctype="multipart/form-data" 必须放在HiddenHttpMethodFilter过滤器之前-->
    <filter>
        <filter-name>MultipartFilter</filter-name>
        <filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
        <init-param>
            <param-name>multipartResolverBeanName</param-name>
            <!--spring中配置的id为multipartResolver的解析器-->
            <!-- 需要注意的是,由于xml加载顺序的问题,multipartResolver必须配置在filter前面先加载的配置文件中,例<context-param>中,普通的文件上传不需要配置 -->
            <param-value>multipartResolver</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>MultipartFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <!-- 请求method支持 put 和 delete 必须添加该过滤器
          作用:可以过滤所有请求,并可以分为四种
             使用该过滤器需要在前端页面加隐藏表单域 
            <input type="hidden" name="_method" value="请求方式(put/delete)"-->
    <filter>
        <filter-name>hiddenHttpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>hiddenHttpMethodFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    
    
    

    <!--将Spring容器与Web容器结合的更加密切。(非必需)与scope=”request”搭配使用:<bean id="role" class="spring.chapter2.maryGame.Role" scope="request"/> -->
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <!-- 将Web容器与spring容器进行整合。(必须有) -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext.xml
        </param-value>
    </context-param>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/springmvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    
    <!-- 所有属于改该属性组的JSP的头部添加文件/WEB-INF/jsp/system/common.jsp -->
    <!-- <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jsp</url-pattern>
            <include-prelude>/WEB-INF/jsp/system/common.jsp</include-prelude>
        </jsp-property-group>
    </jsp-config> -->
</web-app>

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: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">
    <!-- 配置文件上传解析器 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 
         <!-- 指定所上传文件的总大小不能超过20M。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 --> 
         <property name="maxUploadSize" value="20000000"/>
         <property name="defaultEncoding" value="utf-8"></property>
    </bean>    
</beans>

springmvc.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"
    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:property-placeholder location="classpath:properties/*.properties"/>
    
    <import resource="springmvc-*.xml"/>
    
    <!--SpringMVC使用 @ResponseBody 注解返回的字符编码为IOS-8859-1-->
    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/plain;charset=UTF-8</value>
                        <value>text/html;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
</beans>

spring-dao.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"
    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">
    
    <!-- 配置数据源 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="${dataSource.url}"></property>
        <property name="user" value="${dataSource.username}"></property>
        <property name="password" value="${dataSource.password}"></property>
        <!-- 每60秒检查所有连接池中的空闲连接。Default: 0 -->
        <property name="idleConnectionTestPeriod" value="60" />
        <!-- 初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 --> 
        <property name="initialPoolSize" value="5" />
        <!-- 最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
        <property name="maxIdleTime" value="60" />
        <!-- 连接池中保留的最大连接数。Default: 15 -->
        <property name="maxPoolSize" value="10" />
        <!-- 连接池中保留的最小连接数。 -->
        <property name="minPoolSize" value="5" />
        <!-- JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 
          属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。 
          如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->
          <property name="maxStatements" value="100" />
        <!-- maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0  -->
        <property name="maxStatementsPerConnection" value="3" />
        <!-- 定义所有连接测试都执行的测试语句。在使用连接测试的情况下这个显著提高测试速度。注意: 
          测试的表必须在初始数据源的时候就存在。Default: null -->
          <property name="preferredTestQuery" value="select 1" />
        <!-- 定义在从数据库获取新连接失败后重复尝试的次数。Default: 30-->
        <property name="acquireRetryAttempts" value="3" />
        <!-- 两次连接中间隔时间,单位毫秒。Default: 1000 -->
        <property name="acquireRetryDelay" value="1000" />
        <!-- 当连接池用完时客户端调用getConnection()后等待获取新连接的时间,超时后将抛出 
          SQLException,如设为0则无限期等待。单位毫秒。Default: 0 -->
          <property name="checkoutTimeout" value="30000" />
    </bean>
    
    <!-- 配置sqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 注入数据源 -->
        <property name="dataSource" ref="dataSource"/>
        <!-- 扫描java bean,自动使用别名 -->
        <property name="typeAliasesPackage" value="com.wyj.bean"/>
        <!-- 扫描mybatis的SQL配置文件 -->
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
        
        <!-- PageHelper 分页插件 -->
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageHelper">
                    <property name="properties">
                        <value>
                            dialect=mysql
                        </value>
                    </property>
                </bean>
            </array>
        </property>
    </bean>
    
    <!-- 扫描Dao接口包 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
        <property name="basePackage" value="com.wyj.dao"/>
    </bean>
</beans>

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:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    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/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- 扫描service包 -->
    <context:component-scan base-package="com.wyj.service"/>
    <!-- 配置事务管理器 -->
    <bean id="transactionManager"  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource"/>
        <property name="rollbackOnCommitFailure" value="true"/>
    </bean>
    
    <!-- 事务采用全注解方式 使用@Transactional进行声明式事务管理需要声明下面这行-->
    <tx:annotation-driven transaction-manager="transactionManager"/>
    
    
    <!-- 通知 -->
    <!-- <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            传播行为
            <tx:method name="save*" propagation="REQUIRED"/> 回滚(增删改)
            <tx:method name="query*" propagation="SUPPORTS" read-only="true"/> 有没有事务都可以(查看)
        </tx:attributes>
    </tx:advice> -->
    
    <!-- 切面配置在这 -->
    <!-- <aop:aspectj-autoproxy/>
    <aop:config>
        <aop:pointcutid="transactionPointCut" expression="execution(*cn.edu.nuc.service..*.*(..))" />
        <aop:advisoradvice-ref="txAdvice" pointcut-ref="transactionPointCut"/>
    </aop:config> -->
</beans>

spring-web.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"
    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">
    <!-- 开启注解映射的支持 -->
    <mvc:annotation-driven/>
    <!-- 允许对静态资源文件的访问 --> 
    <mvc:default-servlet-handler/>
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**"/>
            <mvc:exclude-mapping path="/login/**"/>
            <!-- 排出拦截的静态资源 -->
            <mvc:exclude-mapping path="/css/**"/>
            <mvc:exclude-mapping path="/js/**"/>
            <mvc:exclude-mapping path="/images/**"/>
            <mvc:exclude-mapping path="/api/**"/>
            <bean class="com.wyj.controller.interceptor.SessionInterceptor"/>
        </mvc:interceptor>
    </mvc:interceptors>
    <!-- 自动扫描的包名 -->
    <context:component-scan base-package="com.wyj.controller"/>
    <!-- 配置视图解析器 -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/jsp"/>
        <property name="suffix" value=".jsp"></property>
    </bean>
    
</beans>

jdbc.properties

dataSource.url=jdbc:mysql://localhost/comment?useUnicode=true&characterEncoding=utf8
dataSource.username=root
dataSource.password=123456


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值