最近在研究redis,所以简单的搭建了一个框架用来学习。这里做个笔记来记录下。
此框架包含spring的缓存注解支持,配置文件去掉了一些不必要的其它业务配置,只展示了一些基本配置
1.mybatis相关配置文件
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 配置数据源 -->
<bean name="datasource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="jdbc:mysql://${jdbc.url}/test" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="1" />
<property name="minIdle" value="1" />
<property name="maxActive" value="20" />
</bean>
<!--配置sqlSessionFactory -->
<bean name="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="datasource"></property>
<property name="mapperLocations" value="classpath:mapper/*.xml" />
</bean>
<!-- 配置自动扫描mapper接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.ahpu.redis.mapper" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
</beans>
2.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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache"
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/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd">
<!-- 引入配置文件 -->
<context:property-placeholder location="classpath:/config/config.properties" />
<!-- 注解支持 -->
<context:annotation-config />
<!-- 组件扫描com.test目录下的所有文件 -->
<context:component-scan base-package="com.ahpu.redis.service" />
<!-- redis缓存配置 -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxWaitMillis" value="${redis.maxWait}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean>
<!-- 配置connectionFactory -->
<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="poolConfig" ref="poolConfig" />
</bean>
<!-- 配置redisTemplate -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="connectionFactory" />
</bean>
<!-- 配置cacheManager 用于管理缓存 -->
<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager">
<constructor-arg name="redisOperations" ref="redisTemplate" />
</bean>
<!-- 添加缓存注解支持 可以支持spring的注解 @Cacheable、@CacheEvict等 -->
<cache:annotation-driven cache-manager="cacheManager" proxy-target-class="true" />
</beans>
3.springMVC相关配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
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-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!-- 配置自动扫描的包,让其扫描 com.ahpu.redis.controller下面的所有包 -->
<context:component-scan base-package="com.ahpu.redis.controller" />
<!-- 配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 注解支持 -->
<mvc:annotation-driven/>
<!-- 定义无Controller的path<->view直接映射 -->
<mvc:view-controller path="/" view-name="redirect:/index" />
</beans>
分享到:
相关推荐
本项目是基于spring4+springmvc+mybatis+redis缓存 注解方式以及spring-session共享session搭建的完整实例。
spring集成springmvc,mybatis,redis,redis采用sentinel哨兵模式 高可用,并基于注解使用redis缓存
报表后端采用技术: SpringBoot整合SSM(Spring+Mybatis-plus+ SpringMvc),spring security 全注解式的权限管理和JWT方式禁用Session,采用redis存储token及权限信息 报表前端采用Bootstrap框架,结合Jquery Ajax,...
shiro作为安全框架,主流技术 几乎零XML,极简配置 两套UI实现(bootstrap+layer ui),可以自由切换 报表后端采用技术: SpringBoot整合SSM(Spring+Mybatis-plus+ SpringMvc),spring security 全注解式的权限管理和...
构建Spring+Springmvc+Mybatis框架,丰富框架的功能,后续集成日志插件log4j、logback,集成Druid连接池监控,集成Redis缓存,office文件操作插件poi等。 1.基于mvc实现基本的数据增删改查操作。 2.已经分别集成log4...
本项目架构采用Mybatis+Spring+SpringMVC作为基础框架 使用apache-shiro作为安全登录及权限验证框架 使用fastjson作数据处理 使用slf4j+log4j做日志记录 使用druid做连接池及监控 采用mysql作为数据库 使用kaptcha并...
架构采用的是SpringMVC4.2.4+mybatis3.4.4+ehcache+redis+shiro1.2.2 虽然redis集成了,但是我自己写的SessionDao有些问题目前就还是用的shiro的EnterpriseCacheSessionDAO,因此就没有用redis来缓存Session,但是集成...
●Spring+SpringMVC+Mybatis+JDK1.8+Maven+Quartz+Freemarker+Redis+EasyUI 项目介绍: ● 为了方便管理公司客户和维护客户关系,利用相应的信息技术以及互联网技术来协调企业与顾客间在销售、营销和服务上的交互...
MyBatis的框架,添加四郎权限控制,AOP日志管理与异常统一处理,Redis的缓存,ActiveMQ的通讯等功能: 5)基于SSM框架简单的后台权限管理系统,整合spring + springmvc + shiro + mybatis + esayui。包含许多基础...
本项目针对初学spring、springmvc、mybatis、框架者,配置勒redis缓存,项目内都有详细的注解声明。!!!!!!!!!
# demoWeb ...Spring Cache增加redis缓存实现 Mybatis使用二级缓存,增加redis实现 增加reactJs 增加Mybatis插件pageHelper,Mapper 1.1.12 使用draft富文本编辑器 增加ant design 代码生成器功能增强
# demoWeb 一个基于SpringMVC的web框架 1.0.5 从web项目迁移成maven项目 ...Spring Cache增加redis缓存实现 Mybatis使用二级缓存,增加redis实现 增加reactJs 增加Mybatis插件pageHelper,Mapper doc内有相关文档
如果你是开发的小白,建议你学完Spring,SpringMVC,MyBatis框架后再来学习本门课程,学完以后会让你完全体验到企业级开发的流程.本课程收获:在职开发人员学完后会让你的薪资更高,让你更了解互联网是如何解决高并发,学...
# demoWeb ...Spring Cache增加redis缓存实现 Mybatis使用二级缓存,增加redis实现 增加reactJs 增加Mybatis插件pageHelper,Mapper 1.1.12 使用draft富文本编辑器 增加ant design 代码生成器功能增强
项目基于 jdk1.8 采用 Spring Boot 框架 集成了分布式任务调度框架 Quartz ,任务存储于数据库。 使用SpringMVC作为路由控制, 集成 Swagger2 提供实时 RESTful API文档。...集成了 Spring data redis,提供缓存服务。
- 在Controller中使用@PreAuthorize等注解需要在spring-web配置文件中扫描security包下的类 6. 引用application.properties中的属性的方式:@ConfigurationProperties(prefix = "spring.mail") + @Component + ...
10.2 Spring的缓存抽象 146 10.2.1 基本概念 146 10.2.2 整合项目 146 10.2.3 CacheEnable注解 148 10.2.4 Cache注解 150 10.3 整合redis 154 10.3.1 在Docker上安装redis 154 10.3.2 Redis的Template 154 10.3.3 ...
ERP_day14_Shoir颗粒认证-redis缓存机制提升软件性能_svn协作开发 ERP_day15项目展示 13-Mybatis(学习2天) MyBatis_day01;mybatis简介--入门 MyBatis_day02.输入输出映射.动态sql-关联查询.myBatis整合spring,...
7.2使用Redis集成缓存 37 八、 热部署 37 8.1 什么是热部署 37 8.2 项目演示案例 37 8.3 热部署原理 37 8.4 Devtools依赖 38 8.5 Devtools原理 38 九、 监控管理 38 Actuator监控应用 38 Maven依赖 38 YML...