2.ssm框架整合配置文件-查看文章

2.ssm框架整合配置文件

发表于:2017-06-24 09:43:50 分类:博客源码 阅读:916次

image

跟着码码在线老王整合的框架配置文件——其实是copyr 

1.数据库连接配置 jdbc.properties

driverClassName=com.mysql.jdbc.Driver
validationQuery=SELECT 1
jdbc_url=jdbc:mysql://127.0.0.1:3306/blog?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
jdbc_username=root
jdbc_password=password

2.MyBatis配置-只是为了打印测试sql mybatis-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>
    <settings>
        <!-- 打印查询语句 -->
        <setting name="logImpl" value="STDOUT_LOGGING" />
    </settings>

    <!-- mapper已经在spring-mybatis.xml中的sqlSessionFactory配置,这里不再需要配置 -->
    <!--     <mappers> -->
    <!--         <mapper resource="com/a/b/c/dao/BusinessInfoDaoMapper.xml" /> -->
    <!--     </mappers> -->
</configuration>

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

    <!--打开切面编程支持-->
    <aop:aspectj-autoproxy proxy-target-class="true"/>
    <!--打开注解-->
    <context:annotation-config/>
    <context:component-scan base-package="top.ersredma.blog" />
    <context:component-scan base-package="top.ersredma.blog.aop" />
    <context:property-placeholder location="classpath:./top/ersredma/blog/resource/jdbc.properties"/>

    <bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sqlSessionFactory">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation" value="classpath:./top/ersredma/blog/resource/mybatis-config.xml"></property>
        <property name="mapperLocations" value="classpath:./top/ersredma/blog/dao/**.xml"/>
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="top.ersredma.blog.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>

    <!--事务管理 注解方式-->
    <tx:annotation-driven transaction-manager="transactionManager"/>

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

    <bean id="XssAspect" class="top.ersredma.blog.aop.AntiXSSAspect">
    </bean>
    <!--<aop:config>-->
        <!--<aop:aspect ref="XssAspect"/>-->
        <!---->
    <!--</aop:config>-->

    <bean class="com.alibaba.druid.pool.DruidDataSource" id="dataSource" 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="initialSize" value="5"/>
        <!--连接池最大使用连接数据-->
        <property name="maxActive" value="20"/>
        <!--连接池最小空闲-->
        <property name="minIdle" value="0"/>
        <!--初始化最大等待时间-->
        <property name="maxWait" value="6000"/>
        
        <property name="validationQuery" value="${validationQuery}"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testOnReturn" value="false"/>
        <property name="testWhileIdle" value="true"/>
        <!--配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位为毫秒-->
        <property name="timeBetweenEvictionRunsMillis" value="60000"/>
        <!--配置一个连接在池内最小生存时间,单位为毫秒-->
        <property name="minEvictableIdleTimeMillis" value="25200000"/>
        <!--打开removeAbandoned功能-->
        <property name="removeAbandoned" value="true"/>
        <!--30分钟-->
        <property name="removeAbandonedTimeoutMillis" value="1800"/>
        <!--关闭abanded连接时输出错误日志-->
        <property name="logAbandoned" value="true"/>
        <!--监控数据库-->
        <property name="filters" value="mergeStat"/>
    </bean>
</beans>

4.springmvc配置 spring-mvc.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/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


    <mvc:annotation-driven>
        <mvc:message-converters >
            <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <!-- 这里顺序不能反,一定先写text/html,不然ie下出现下载提示 -->
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <mvc:annotation-driven/>
    <context:component-scan base-package="top.ersredma.blog.controller.**">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
    </context:component-scan>
    <!-- 子容器的service 没有事务能力 spring顶级容器 才有service事务能力 -->
    <!--不拦截静态资源-->
    <mvc:annotation-driven />
    <mvc:resources location="/images/" mapping="/images/**"/>
    <mvc:resources location="/css/" mapping="/css/**"/>
    <mvc:resources location="/layer/" mapping="/layer/**"/>
    <mvc:resources location="/js/" mapping="/js/**"/>
    <mvc:resources location="/upload/" mapping="/upload/**"/>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/view/"/>
        <property name="suffix" value=".jsp"/>
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    </bean>

    <!--<mvc:interceptors>-->
        <!--&lt;!&ndash;<bean class="top.aiprogram.interceptor.SpringMvcInterceptor"/>&ndash;&gt;-->
        <!--<mvc:interceptor>-->
            <!--<mvc:mapping path="/user/demo"/>-->
            <!--<bean class="top.aiprogram.interceptor.SpringMvcInterceptor"/>-->
        <!--</mvc:interceptor>-->
    <!--</mvc:interceptors>-->

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="500000"/>
        <property name="maxInMemorySize" value="500000"/>
        <property name="defaultEncoding" value="utf-8"/>
    </bean>
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**"/>
            <!-- 定义在mvc:interceptor下面的表示是对特定的请求才进行拦截的 -->
            <bean class="top.ersredma.blog.interceptor.MyInterceptor"/>
        </mvc:interceptor>
    </mvc:interceptors>

</beans>


关键词:blog源码,配置


验证码:

  1. author
    窝阔台(伪装者) 2017-11-08 16:23:39
    halou
  2. author
    乔寨主(伪装者) 2017-06-27 13:41:49
    回复:王罕

    这套系统花了多久写完的啊

    十天吧.主要要看儿子,不然会快点.
  3. author
    王罕(伪装者) 2017-06-27 12:39:21
    这套系统花了多久写完的啊