笔记

在Spring中如何使用AOP?

  1. Spring是如何切换JDK动态代理CGLIB的?
  • spring.aop.proxy-target-class=true (在下方第二个链接中,原生doc中提到过)
  1. @Aspect生命切面
  • @Before
  • @After
  • @Around

Redis

  1. 广泛使用的内存缓存
  2. 常见的数据结构:
  • String
  • List
  • Set
  • Hash
  • ZSet
  1. Redis为什么快?
  • 完全基于内存
  • 优秀的数据结构设计
  • 单一线程,避免上下文切换开销
  • 事件驱动,非阻塞

浏览的一些学习资料

Spring Boot中使用AOP统一处理Web请求日志

Proxying mechanisms: 代理机制(spring doc)

Aspect Oriented Programming with Spring: 使用AOP进行面向切面编程(spring doc)

2020年2月8日 更新:

如何使用再spring boot中redis?

这里我使用了docker容器

  1. 首先引入pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
  1. docker中运行redis,端口为6379
docker run -p 6379:6379 -d redis
  1. 创建了一个名为config的package,并创建了config/AppConfig.java
@Configuration
public class AppConfig {
@Bean
RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(factory);
return redisTemplate;
}
}

使用AOP实现redis的缓存(代码)

@Aspect
@Configuration
public class CacheAspect {
// Map<String, Object> cache = new HashMap<>();
@Autowired
RedisTemplate<String,Object> redisTemplate; @Around("@annotation(emmm.anno.Cache)")
public Object cache(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); String methodName = signature.getName(); Object cachedValue = redisTemplate.opsForValue().get(methodName);
// Object cachedValue = cache.get(methodName); if (cachedValue != null) {
System.out.println("from cache");
return cachedValue;
} else {
System.out.println("from db");
Object realValue = joinPoint.proceed();
redisTemplate.opsForValue().set(methodName, realValue);
// cache.put(methodName, realValue);
return realValue;
}
}
}

补:参考到的网址:

docker->redis

docker start

spring doc -> spring data redis

Spring Boot中使用Redis数据库

今日份学习: Spring中使用AOP并实现redis缓存?的更多相关文章

  1. Spring学习笔记(四)—— Spring中的AOP

    一.AOP概述 AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善.O ...

  2. Spring 中基于 AOP 的 @AspectJ

    Spring 中基于 AOP 的 @AspectJ @AspectJ 作为通过 Java 5 注释注释的普通的 Java 类,它指的是声明 aspects 的一种风格. 通过在你的基于架构的 XML ...

  3. Spring 中基于 AOP 的 XML架构

    Spring 中基于 AOP 的 XML架构 为了使用 aop 命名空间标签,你需要导入 spring-aop j架构,如下所述: <?xml version="1.0" e ...

  4. Spring中的AOP

    什么是AOP? (以下内容来自百度百科) 面向切面编程(也叫面向方面编程):Aspect Oriented Programming(AOP),通过预编译方式和运行期动态代理实现程序功能的统一维护的一种 ...

  5. 学习spring中遇见的问题

    报错: Unexpected exception parsing XML document from class path resource [applicationContext.xml]; nes ...

  6. Spring中关于AOP的实践之概念

    一.什么是AOP AOP:也称作面向切面编程 在分享几个概念执行我想先举个栗子(可能例子举得并不是特别恰当): 1.假如路人A走在大街上,被一群坏人绑架了: 2.警察叔叔接到报警迅速展开行动:收集情报 ...

  7. Spring中的AOP 专题

    Caused by: java.lang.IllegalArgumentException: ProceedingJoinPoint is only supported for around advi ...

  8. spring中的AOP 以及各种通知 配置

    理解了前面动态代理对象的原理之后,其实还是有很多不足之处,因为如果在项目中有20多个类,每个类有100多个方法都需要判断是不是要开事务,那么方法调用那里会相当麻烦. spring中的AOP很好地解决了 ...

  9. 2018.12.24 Spring中的aop演示(也就是运用aop技术实现代理模式)

    Aop的最大意义是:在不改变原来代码的前提下,也不对源代码做任何协议接口要求.而实现了类似插件的方式,来修改源代码,给源代码插入新的执行代码. 1.spring中的aop演示 aop:面向方面编程.不 ...

随机推荐

  1. Session服务器之Session复制!

    全部运行在Tomcat下 第一台主机:192.168.200.131  安装nginx 修改hosts文件 [root@localhost ~]# vim /etc/hosts 192.168.200 ...

  2. SystemC中文教程一

    SystemC是什么 首先, SystemC不是一门新的语言,而是基于C++开发的library:因此,你所熟悉的C++知识都可以在SystemC建模时使用:理论上来说,SystemC library ...

  3. Navigating to current location ("/") is not allowed

    main.js import Router from 'vue-router' // 这个是为了避免一个报错 const originalPush = Router.prototype.push; R ...

  4. JAVA中final关键字的作用

    一.final关键字的功能概述 final关键字可以用来修饰引用.方法和类. 1.用来修饰一个引用 如果引用为基本数据类型,则该引用为常量,该值无法修改: 如果引用为引用数据类型,比如对象.数组,则该 ...

  5. mapreduce程序执行过程

    1.客户端程序,设置作业相关的配置和计算输入分片信息,向RM获取一个JOBID,提交作业信息(分片)到以作业ID为目录下,通知APP——MASTER 2.APP——MASTER,读取指定目录下的作业信 ...

  6. 11 JavaScript Number原始值&对象&科学记数法&范围&进制转换&溢出Infinity&NaN

    JavaScript Number对象 是经过封装的能处理数字值的对象 由Number()构造器创建 只有一种数字类型 可以使用也可以不使用小数点书写数字 JavaScript原始值与对象: 在Jav ...

  7. Eclipse开发快捷键

    ctrl+alt+r:查找资源 ctrl+o:快速outLine ctrl+e:快速切换编辑器 ctrl+./ctrl+1:下一个错误修改

  8. 什么是Socket:

    先了解一些前提: 网络由下往上分为 物理层 .数据链路层 . 网络层 . 传输层 . 会话层 . 表现层 和 应用层.通过初步了解,我知道IP协议对应于网络层,TCP协议对应于传输层,而HTTP协议对 ...

  9. Python环境搭建-3 Python下载

    python环境搭建 Python是一个跨平台.可移植的编程语言,因此可在windows.Linux和Mac OS X系统中安装使用. 安装完成后,你会得到Python解释器环境,可以通过终端输入py ...

  10. java 依赖注入

    https://blog.csdn.net/coderder/article/details/51897721 前言 在软件工程领域,依赖注入(Dependency Injection)是用于实现控制 ...