• spring容器的配置和springmvc的配置


    spring容器的配置

    <?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/mvc"
        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-3.0.xsd 
                http://www.springframework.org/schema/mvc 
                http://www.springframework.org/schema/mvc/spring-mvc-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/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-3.0.xsd ">
                
        <!-- 1. 加载数据库配置的属性文件 -->
        <context:property-placeholder location="classpath:jdbc.properties"/>
        
        <!-- 2. 包扫描dao,service -->
        <context:component-scan base-package="cn.itcast.jk.dao,cn.itcast.jk.service"/>
        
        <!-- 3. 数据源dataSource  C3P0 -->
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass" value="${jdbc.driverClassName}"/>
            <property name="jdbcUrl" value="${jdbc.url}"/>
            <property name="user" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
            
            <property name="maxPoolSize" value="${c3p0.pool.maxPoolSize}"/>
            <property name="minPoolSize" value="${c3p0.pool.minPoolSize}"/>
            <property name="initialPoolSize" value="${c3p0.pool.initialPoolSize}"/>
            <property name="acquireIncrement" value="${c3p0.pool.acquireIncrement}"/>
        </bean>
        
        <!-- 4. SessionFactory -->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <!-- 整合mybatis,包扫描 mapper文件 -->
            <property name="configLocation" value="classpath:sqlMapConfig.xml"/>
            <property name="mapperLocations" value="classpath:cn/itcast/jk/mapper/*.xml"/>
        </bean>
        
        
        
        <!-- 整合sping jdbcTemplate -->
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="dataSource"/>
        </bean>
        <bean id="sqlDao" class="cn.itcast.common.springdao.SqlDao">
            <property name="jdbcTemplate" ref="jdbcTemplate"/>
        </bean>
        
        <!-- 5. 事务 -->
        <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"/>
        </bean>
        
        <tx:advice id="txAdvice" transaction-manager="txManager">
            <tx:attributes>
                <tx:method name="insert*" propagation="REQUIRED"/>
                <tx:method name="update*" propagation="REQUIRED"/>
                <tx:method name="delete*" propagation="REQUIRED"/>
                <tx:method name="save*" propagation="REQUIRED"/>
                
                <tx:method name="find*" read-only="true"/>
                <tx:method name="get*" read-only="true"/>
                <tx:method name="view*" read-only="true"/>
            </tx:attributes>
        </tx:advice>
        
        <aop:config>
            <aop:pointcut expression="execution(* cn.itcast.jk.service.*.*(..))" id="txPointcut"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
        </aop:config>
                
    </beans>

    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/mvc"
        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-3.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-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/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-3.0.xsd ">
        
        <mvc:annotation-driven></mvc:annotation-driven> 
        
        <!-- 1. 包扫描 controller -->
        <context:component-scan base-package="cn.itcast.jk.controller"/>
        
        <!-- 2. 内部资源视图解析器 -->
        <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/pages"/>
            <property name="suffix" value=""/>
        </bean>
        
    </beans>

    oracle和mysql的配置信息

    #jdbc.driverClassName=com.mysql.jdbc.Driver
    #jdbc.url=jdbc:mysql://localhost:3306/jkdb?characterEncoding=utf-8
    #jdbc.username=root
    #jdbc.password=521314
    
    jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
    jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:ORCL
    jdbc.username=jkdb
    jdbc.password=123456
    
    c3p0.pool.maxPoolSize=20
    c3p0.pool.minPoolSize=5
    c3p0.pool.initialPoolSize=3
    c3p0.pool.acquireIncrement=2
  • 相关阅读:
    如何解决IOS 下固定定位fixed 失效问题?
    fixed定位按钮在底部,键盘弹起,按钮被顶上去
    js对象和jquery对象相互转换
    # js中substr、substring、indexOf、lastIndexOf的用法
    在新页面中返回到前一页浏览的历史位置
    vue-cli构建的项目中axios的请求方式及跨域处理
    搭建基于Express框架运行环境 及其启动方式
    微信小程序Page中data数据操作和函数调用
    linux的一些基本操作
    JavaScript对象
  • 原文地址:https://www.cnblogs.com/fengjunming/p/7954215.html
Copyright © 2020-2023  润新知