spring-context.xml 和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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    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/tx
                        http://www.springframework.org/schema/tx/spring-tx.xsd
                        http://www.springframework.org/schema/task
                        http://www.springframework.org/schema/task/spring-task.xsd">

    <!-- 引入配置文件 -->
   <context:property-placeholder location="classpath:jdbc.properties,classpath*:sysConfig.properties"/>
    

    <bean id="activity_ssf" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="ds_activity" />
        <!-- 自动扫描mapping.xml文件 -->
        <property name="mapperLocations" value="classpath:com/url/mapping/*.xml"></property>
        <!-- 指定实体类包名,根据类名自动进行mybatis类型映射 -->
        <property name="typeAliasesPackage" value="com.url.pojo"></property>
    </bean>

    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.url.dao" />
        <property name="sqlSessionFactoryBeanName" value="test_ssf"></property>
    </bean>
    
    <!-- <aop:aspectj-autoproxy /> -->
    <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
    <bean id="tm_sns_activity"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="ds_test" />
    </bean>
    
    <!-- 动态数据源-->
    <bean id="ds_activity" class="com.test.base.DynamicDataSource">
        <property name="targetDataSources">
            <map key-type="java.lang.String">
                <entry value-ref="ds_test" key="ds_test"></entry>
            </map>
        </property>
    </bean>
    
    <bean id="ds_test" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}" />
        <property name="initialSize" value="${jdbc.initialSize}"></property>
        <property name="maxActive" value="${jdbc.maxActive}"/>
        <property name="maxIdle" value="${jdbc.maxIdle}" />
        <property name="minIdle" value="${jdbc.minIdle}" />
        <property name="maxWait" value="${jdbc.maxWait}" />
        <property name="testOnBorrow" value="${jdbc.testOnBorrow}" />
        <property name="testOnReturn" value="${jdbc.testOnReturn}" />
        <property name="testWhileIdle" value="${jdbc.testWhileIdle}" />
        <property name="removeAbandoned" value="${jdbc.removeAbandoned}" />
        <property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
        <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
        <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />
        <property name="logAbandoned" value="${jdbc.logAbandoned}" />
        <property name="connectionInitSqls" value="${connectionInitSqls}"/>
    </bean>
    <bean id="test1" class="com.ptest14">  
        <property name="str" value="test2"/>
    </bean>
</beans>

 

 

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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    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/tx
                        http://www.springframework.org/schema/tx/spring-tx.xsd
                        http://www.springframework.org/schema/task
                        http://www.springframework.org/schema/task/spring-task.xsd">

    <!-- 引入配置文件 -->
   <context:property-placeholder location="classpath:jdbc.properties,classpath*:sysConfig.properties"/>
    

    <bean id="activity_ssf" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="ds_activity" />
        <!-- 自动扫描mapping.xml文件 -->
        <property name="mapperLocations" value="classpath:com/url/mapping/*.xml"></property>
        <!-- 指定实体类包名,根据类名自动进行mybatis类型映射 -->
        <property name="typeAliasesPackage" value="com.url.pojo"></property>
    </bean>

    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.url.dao" />
        <property name="sqlSessionFactoryBeanName" value="test_ssf"></property>
    </bean>
    
    <!-- <aop:aspectj-autoproxy /> -->
    <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
    <bean id="tm_sns_activity"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="ds_test" />
    </bean>
    
    <!-- 动态数据源-->
    <bean id="ds_activity" class="com.test.base.DynamicDataSource">
        <property name="targetDataSources">
            <map key-type="java.lang.String">
                <entry value-ref="ds_test" key="ds_test"></entry>
            </map>
        </property>
    </bean>
    
    <bean id="ds_test" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}" />
        <property name="initialSize" value="${jdbc.initialSize}"></property>
        <property name="maxActive" value="${jdbc.maxActive}"/>
        <property name="maxIdle" value="${jdbc.maxIdle}" />
        <property name="minIdle" value="${jdbc.minIdle}" />
        <property name="maxWait" value="${jdbc.maxWait}" />
        <property name="testOnBorrow" value="${jdbc.testOnBorrow}" />
        <property name="testOnReturn" value="${jdbc.testOnReturn}" />
        <property name="testWhileIdle" value="${jdbc.testWhileIdle}" />
        <property name="removeAbandoned" value="${jdbc.removeAbandoned}" />
        <property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
        <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
        <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />
        <property name="logAbandoned" value="${jdbc.logAbandoned}" />
        <property name="connectionInitSqls" value="${connectionInitSqls}"/>
    </bean>
    <bean id="test1" class="com.ptest14">  
        <property name="str" value="test2"/>
    </bean>
</beans>

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值