ssm框架中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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    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.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    ">
    <!-- 开启注解扫描 -->
    <context:component-scan base-package="cn.dtw"></context:component-scan>
    <!-- 读取配置文件 -->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    <!-- 数据源 使用c3p0连接,需要jar包支持 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="jdbcUrl" value="${jdbcUrl}"></property>
        <property name="driverClass" value="${driverClass}"></property>
        <property name="user" value="${user}"></property>
        <property name="password" value="${password}"></property>
    </bean>

    <!-- 集成Mybatis(sqlSessionFactory )-->
    <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="typeAliasesPackage" value="cn.dtw"></property>
    </bean>

    <!-- 映射帮助类 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sessionFactory"></property>
        <property name="basePackage" value="cn.dtw.dao"></property>
    </bean>

    <!-- 事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!-- 事务注解 -->
    <tx:annotation-driven/>

    <!-- mvc注解驱动 -->
    <mvc:annotation-driven/>
    <!-- 处理静态资源 -->
    <mvc:default-servlet-handler/>



    <!-- 注册异常处理 -->
    <bean id="exceptionHandler" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="defaultErrorView" value="error"></property>
        <property name="exceptionAttribute" value="exp"></property>
        <property name="exceptionMappings">
            <props>
                <prop key="cn.dtw.exception.MyException">myError</prop>
            </props>
        </property>
    </bean>

    <!-- 支持上传文件 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 指定默认的编码格式,默认是ISO-8859-1 -->
        <property name="defaultEncoding" value="utf-8"></property>
        <!-- 上传文件的最大值,单位是字节 -->
        <property name="maxUploadSize" value="10000000"></property>
        <!-- 上传文件的临时文件夹 -->
        <property name="uploadTempDir" value="tempDir"></property>
    </bean>

    <!-- 视图处理 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

    <!-- 使用动态代理技术 -->
    <!--    
        <bean id="logAspect" class="cn.dtw.aop.LogAspect"></bean>
        <aop:config>
            切入点
            <aop:pointcut expression="execution(public java.lang.Integer addCar(cn.dtw.entity.Car))" id="pointcut"/>        
            <aop:pointcut expression="execution(* cn.dtw.service.*.*(..))" id="pointcut"/>
            切入面
            <aop:aspect ref="logAspect">
                <aop:before method="before" pointcut-ref="pointcut"/>
            </aop:aspect>
        </aop:config> 
    -->
    <bean id="logAspect" class="cn.dtw.aop.LogAspect"></bean>
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy>

</beans>
————————————————
版权声明:本文为CSDN博主「Faith_chao」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Faith_chao/article/details/79755399
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值