ssm之使用JdbcTemplate进行mysql数据库数据操作

<?xml version="1.0" encoding="UTF-8"?>
<beans default-lazy-init="true"
    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:util="http://www.springframework.org/schema/util" xmlns:security="http://www.springframework.org/schema/security"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    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/util http://www.springframework.org/schema/util/spring-util.xsd
            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
            http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd
            http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
            http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
            
<!--    <bean name="propertyConfigurer_core3"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" 
    p:ignoreUnresolvablePlaceholders="true" 
    p:ignoreResourceNotFound="true">
        <property name="locations">
            <list>
                <value>file:${APP_FILE}/cfg/system.properties</value>
            </list>
        </property>
    </bean>-->
    


    <bean id="redisHelper" class="com.yh.service.cache.redis.impl.ClusterRedisHelper"
            init-method="init" destroy-method="destroy">
        <property name="clusterUrl">
            <list>
                <value>${redis.url1}</value>
                <value>${redis.url2}</value>
                <value>${redis.url3}</value>
            </list>
        </property>
        <property name="password" value="${redis.a}"></property>
        <property name="name" value="foliage_yh"></property>
        <property name="maxIdle" value="${redis.maxIdel}"></property>
        <property name="maxTotal" value="${redis.maxTotal}"></property>
        <property name="maxWait"  value="${redis.maxWait}"></property>
    </bean>
    <bean id="cacheDao" class="com.yh.impl.CacheDaoImpl">
        <property name="redisHelper" ref="redisHelper"/>
    </bean>

    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />

        <property name="name" value="${dataSource.name}" />
        <property name="initialSize" value="${dataSource.initialSize}" />
        <property name="minIdle" value="${dataSource.minIdle}" />
        <property name="maxActive" value="${dataSource.maxActive}" />

        <property name="maxWait" value="${dataSource.maxWait}" />
        <property name="useUnfairLock" value="${dataSource.useUnfairLock}" />

        <property name="validationQuery" value="${dataSource.validationQuery}" />
        <property name="testOnBorrow" value="${dataSource.testOnBorrow}" />
        <property name="testOnReturn" value="${dataSource.testOnReturn}" />
        <property name="testWhileIdle" value="${dataSource.testWhileIdle}" />

        <property name="timeBetweenEvictionRunsMillis" value="${dataSource.timeBetweenEvictionRunsMillis}" />
        <property name="minEvictableIdleTimeMillis" value="${dataSource.minEvictableIdleTimeMillis}" />
    </bean>

    <bean id="jdbcTemplate"
          class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <bean id="txManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception" />
            <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception" />
            <tx:method name="get*" read-only="true" />
        </tx:attributes>
    </tx:advice>
    <bean id="dataBaseDao" class="com.yanghuan.dao.impl.DataBaseDaoImpl">
        <property name="jdbcTemplate" ref="jdbcTemplate"/>
    </bean>

    <aop:config>
        <aop:pointcut id="daoPointCuts"
                      expression="execution(* com.yh.DeviceUserServiceImpl.*DbTran(..)) or
            execution(* com.yh.DeviceyhServiceImpl.*DbTran(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="daoPointCuts"/>
    </aop:config>
    
    
    <bean id="abstractService" abstract="true">
        <property name="cacheDao" ref="cacheDao" />
        <property name="dataBaseDao" ref="dataBaseDao"/>
    </bean>
    
    <bean id="deviceyhService" parent="abstractService" class="com.yh.DeviceyhServiceImpl">
        <property name="conf" ref="deviceRoleConf"/>
        <property name="converter" ref="deviceyhLastDataConverter"/>
        <property name="deviceService" ref="deviceyhService"/>
    </bean>
    <dubbo:service interface="com.yh.DeviceService" ref="deviceyhService"></dubbo:service>
</beans>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值