1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:p="http://www.springframework.org/schema/p" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xmlns:tx="http://www.springframework.org/schema/tx" 7 xmlns:mvc="http://www.springframework.org/schema/mvc" 8 xmlns:aop="http://www.springframework.org/schema/aop" 9 xmlns:cache="http://www.springframework.org/schema/cache" 10 xsi:schemaLocation="http://www.springframework.org/schema/beans 11 http:// 12 http:// 13 http:// 14 http:// 15 http:// "> 16 17 <!-- 扫描dao,service --> 18 <context:component-scan base-package="com.sl.user.service" /> 19 <context:component-scan base-package="com.sl.user.service.*" /> 20 <context:component-scan base-package="com.sl.user.redis" /> 21 <!-- 启用注解 --> 22 <context:annotation-config/> 23 <!-- 启动缓存注解 --> 24 <cache:annotation-driven/> 25 26 <!-- MyBatis start --> 27 <!-- 配置dataSource DriverManagerDataSource--> 28 <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 29 <property value="com.MySQL.jdbc.Driver"></property> 30 <property value="jdbc:mysql://127.0.0.1:3306/test"></property> 31 <property value="root"></property> 32 <property value="root"></property> 33 </bean> 34 35 <!-- MyBatis配置 SqlSessionFactoryBean --> 36 <bean class="org.mybatis.spring.SqlSessionFactoryBean"> 37 <property ref="dataSource"></property> 38 <property value="classpath:config/mybatis.xml"></property> 39 <property value="classpath:mapper/UserMapper.xml"></property> 40 </bean> 41 42 <!-- mybatis自动扫描加载Sql映射文件/接口 : MapperScannerConfigurer 43 sqlSessionFactory 44 basePackage:指定sql映射文件/接口所在的包(自动扫描) --> 45 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 46 <property ref="sessionFactory"></property> 47 <property value="com.sl.user.dao"></property> 48 </bean> 49 50 <!-- 事务管理 DataSourceTransactionManager--> 51 <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 52 <property ref="dataSource"></property> 53 </bean> 54 55 <!-- 使用声明式事务 transaction-manager:引用上面定义的事务管理器--> 56 <tx:annotation-driven transaction-manager="txManager"></tx:annotation-driven> 57 58 <!-- MyBatis end --> 59 60 <!-- 配置redis部分 start --> 61 62 <!-- 配置redis连接池 JedisPoolConfig--> 63 <bean class="redis.clients.jedis.JedisPoolConfig"> 64 <property value="300" /> 65 <property value="600" /> 66 </bean> 67 68 <!-- 配置CoonnectionFactory JedisConnectionFactory--> 69 <bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> 70 <property value="127.0.0.1"></property> 71 <property value="6379"></property> 72 <property ref="poolConfig"></property> 73 </bean> 74 75 <!-- 配置redisTemplate StringRedisTemplate--> 76 <bean class="org.springframework.data.redis.core.StringRedisTemplate"> 77 <property ref="connFactory"/> 78 </bean> 79 80 <bean class="org.springframework.cache.support.SimpleCacheManager"> 81 <property> 82 <set> 83 <bean class="com.sl.user.redis.RedisUtil"> 84 <property ref="redisTemplate" /> 85 <property value="User"/> 86 <!-- User名称要在类或方法的注解中使用 --> 87 </bean> 88 </set> 89 </property> 90 </bean> 91 92 </beans>
Spring与Mybatis基于注解整合Redis
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/ff2adc3d3806c1b9812a67878a0ff0d1.html