美文网首页
applicationContext.xml和sqlMapCon

applicationContext.xml和sqlMapCon

作者: 相信灬你一直在 | 来源:发表于2018-07-21 14:54 被阅读0次

    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:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/aop
        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util-4.0.xsd">
    
    
        <context:property-placeholder location="classpath:db.properties"/>
    
    
        <!-- 数据库连接池 -->
        <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
              destroy-method="close">
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
            <property name="driverClassName" value="${jdbc.driver}" />
            <property name="maxActive" value="10" />
            <property name="minIdle" value="5" />
        </bean>
    
        <!-- Mybatis的工厂 -->
        <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <!-- 核心配置文件的位置 -->
            <property name="configLocation" value="classpath:sqlMapConfig.xml"/>
            <!-- 扫描sql配置文件:mapping需要的xml文件 -->
            <property name="mapperLocations" value="classpath:mapper/*.xml"/>
        </bean>
    
    
        <!-- Mapper动态代理开发  扫描 -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean" />
            <!-- 基本包 -->
            <property name="basePackage" value="cn.e3mall.dao"/>
        </bean>
    
        <!-- 注解事务 -->
        <bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"/>
        </bean>
        <!-- 开启注解 -->
        <tx:annotation-driven transaction-manager="transactionManager"/>
    
    </beans>
    

    sqlMapCongig.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>
        <!-- 设置别名 -->
        <!--<typeAliases>-->
            <!--&lt;!&ndash; 2. 指定扫描包,会把包内所有的类都设置别名,别名的名称就是类名,大小写不敏感 &ndash;&gt;-->
            <!--<package name="cn.e3mall.pojo"/>-->
        <!--</typeAliases>-->
        <!-- 配置分页插件 -->
        <plugins>
            <plugin interceptor="com.github.pagehelper.PageHelper">
                <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
                <property name="dialect" value="mysql"/>
            </plugin>
        </plugins>
    </configuration>
    
    

    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:p="http://www.springframework.org/schema/p"
           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-4.0.xsd
            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">
    
        <!-- 扫描@Controler  @Service   -->
        <context:component-scan base-package="cn.e3mall"/>
        <!-- 注解驱动 -->
        <mvc:annotation-driven/>
    
    
        <!-- 定义文件解释器 -->
        <bean
                id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <!-- 设置默认编码 -->
            <property name="defaultEncoding" value="utf-8"></property>
            <!-- 上传图片最大大小5M-->
            <property name="maxUploadSize" value="5242440"></property>
    
        </bean>
    
        <mvc:resources mapping="/css/**" location="/WEB-INF/css/"/>
        <mvc:resources mapping="/js/**" location="/WEB-INF/js/"/>
        <!--视图解释器-->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/"/>
            <property name="suffix" value=".jsp"/>
        </bean>
    
    </beans>
    

    相关文章

      网友评论

          本文标题:applicationContext.xml和sqlMapCon

          本文链接:https://www.haomeiwen.com/subject/pvyhmftx.html