springmvc文件

    <?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/cache"
       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/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 请求映射对象 -->
    <bean id="requestMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
    <!-- 视图解析器 -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- 前缀 -->
        <property name="prefix" value="/"/>
        <!-- 后缀 -->
        <property name="suffix" value=".jsp"/>
    </bean>
    <!-- 定义文件上传处理解析器 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 限制文件大小 -->
        <property name="maxUploadSize" value="1000000000000000000"/>
    </bean>
    <!-- 注解驱动 -->
    <mvc:annotation-driven/>
    <!-- 默认servlet处理 -->
    <mvc:default-servlet-handler/>
    <!-- 控制层扫描 -->
    <context:component-scan base-package="com.xuetang9.t8.maven.controller"/>
    </beans>

spring-mybatis文件

    <?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 https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">
    <!-- 数据源导入 -->
    <context:property-placeholder location="datasource.properties"/>
    <!-- 定义数据源对象 -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${db.driver}"/>
        <property name="url" value="${db.url}"/>
        <property name="username" value="${db.username"/>
        <property name="password" value="${db.password}"/>
    </bean>
    <!-- 定义SQL会话工厂 -->
    <bean class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="typeAliases" value="java.lang.Integer"/>
    </bean>
    <!-- 定义事物管理对象 -->
    <bean id="transactionManage" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!-- 定义事物增强 -->
    <tx:advice id="interceptor" transaction-manager="transactionManage">
        <tx:attributes>
            <tx:method name="add*" isolation="DEFAULT" propagation="REQUIRED"/>
            <tx:method name="remove*" isolation="DEFAULT" propagation="REQUIRED"/>
            <tx:method name="update*" isolation="DEFAULT" propagation="REQUIRED"/>
            <tx:method name="query*" isolation="DEFAULT" read-only="true"/>
        </tx:attributes>
    </tx:advice>
    <!-- 使用AOP组织事物增强 -->
    <aop:config>
        <aop:pointcut id="mapperPoint" expression="execution(* com.xuetang9.t8.maven.mapper..*.*(..))"/>
    </aop:config>
    <!-- 数据操作层扫描 -->
    <bean id="configurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.xuetang9.t8.maven.mapper"/>
    </bean>
    <!-- 服务层扫描 -->
    <context:component-scan base-package="com.xuetang9.t8.maven.service"/>
    </beans>
最后修改:2019 年 12 月 18 日 12 : 55 AM
如果觉得我的文章对你有用,请随意赞赏