当前位置: 首页 > news >正文

读spring官方文档的一些关键知识点介绍

目录

    • bean definition
    • BeanPostProcessor
    • BeanFactoryPostProcessor
    • @Component and Further Stereotype Annotations
    • AOP Concepts

bean definition

https://docs.spring.io/spring-framework/docs/5.1.3.RELEASE/spring-framework-reference/core.html#beans-child-bean-definitions

A bean definition can contain a lot of configuration information, including constructor arguments, property values, and container-specific information, such as the initialization method, a static factory method name, and so on. A child bean definition inherits configuration data from a parent definition. The child definition can override some values or add others as needed. Using parent and child bean definitions can save a lot of typing. Effectively, this is a form of templating.

bean定义包括了,构造参数、属性值、初始化方法等。可以有父子继承

BeanPostProcessor

https://docs.spring.io/spring-framework/docs/5.1.3.RELEASE/spring-framework-reference/core.html#beans-factory-extension

The BeanPostProcessor interface defines callback methods that you can implement to provide your own (or override the container’s default) instantiation logic, dependency-resolution logic, and so forth. If you want to implement some custom logic after the Spring container finishes instantiating, configuring, and initializing a bean, you can plug in one or more BeanPostProcessor implementations.

You can configure multiple BeanPostProcessor instances, and you can control the order in which these BeanPostProcessor instances execute by setting the order property. You can set this property only if the BeanPostProcessor implements the Ordered interface. If you write your own BeanPostProcessor, you should consider implementing the Ordered interface, too. For further details, see the javadoc of the BeanPostProcessor and Ordered interfaces. See also the note on programmatic registration of BeanPostProcessor instances.

定制化bean, 可以自己去实现bean的实例化、依赖解决。bean的实例化,属性配置,初始化方法都可以进行定制。

自定义BeanPostProcessor需要实现BeanPostProcessor相关接口,并有Order相关接口,可实现按顺序访问。

example:

import org.springframework.beans.factory.config.BeanPostProcessor;public class InstantiationTracingBeanPostProcessor implements BeanPostProcessor {// simply return the instantiated bean as-ispublic Object postProcessBeforeInitialization(Object bean, String beanName) {return bean; // we could potentially return any object reference here...}public Object postProcessAfterInitialization(Object bean, String beanName) {System.out.println("Bean '" + beanName + "' created : " + bean.toString());return bean;}
}

BeanFactoryPostProcessor

https://docs.spring.io/spring-framework/docs/5.1.3.RELEASE/spring-framework-reference/core.html#beans-factory-extension-factory-postprocessors

BeanFactoryPostProcessor operates on the bean configuration metadata. That is, the Spring IoC container lets a BeanFactoryPostProcessor read the configuration metadata and potentially change it before the container instantiates any beans other than BeanFactoryPostProcessor instances.

You can configure multiple BeanFactoryPostProcessor instances, and you can control the order in which these BeanFactoryPostProcessor instances run by setting the order property. However, you can only set this property if the BeanFactoryPostProcessor implements the Ordered interface. If you write your own BeanFactoryPostProcessor, you should consider implementing the Ordered interface, too. See the javadoc of the BeanFactoryPostProcessor and Ordered interfaces for more details.

BeanFactoryPostProcessor操作bean配置元数据,可以读取bean配置,可以bean实例化之前改变元数据,即对BeanDefinition进行干预。

自定义BeanFactoryPostProcessor需要实现BeanFactoryPostProcessor相关接口,并有Order相关接口,可实现按顺序访问

@Component and Further Stereotype Annotations

https://docs.spring.io/spring-framework/docs/5.1.3.RELEASE/spring-framework-reference/core.html#beans-stereotype-annotations

The @Repository annotation is a marker for any class that fulfills the role or stereotype of a repository (also known as Data Access Object or DAO). Among the uses of this marker is the automatic translation of exceptions, as described in Exception Translation.

Spring provides further stereotype annotations: @Component, @Service, and @Controller. @Component is a generic stereotype for any Spring-managed component. @Repository, @Service, and @Controller are specializations of @Component for more specific use cases (in the persistence, service, and presentation layers, respectively). Therefore, you can annotate your component classes with @Component, but, by annotating them with @Repository, @Service, or @Controller instead, your classes are more properly suited for processing by tools or associating with aspects. For example, these stereotype annotations make ideal targets for pointcuts. @Repository, @Service, and @Controller can also carry additional semantics in future releases of the Spring Framework. Thus, if you are choosing between using @Component or @Service for your service layer, @Service is clearly the better choice. Similarly, as stated earlier, @Repository is already supported as a marker for automatic exception translation in your persistence layer.

  • @Service
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component 
public @interface Service {// ....
}

The Component causes @Service to be treated in the same way as @Component.

AOP Concepts

https://docs.spring.io/spring-framework/docs/5.1.3.RELEASE/spring-framework-reference/core.html#aop-introduction-defn

These terms are not Spring-specific. Unfortunately, AOP terminology is not particularly intuitive. However, it would be even more confusing if Spring used its own terminology.

  • Aspect: A modularization of a concern that cuts across multiple classes. Transaction management is a good example of a crosscutting concern in enterprise Java applications. In Spring AOP, aspects are implemented by using regular classes (the schema-based approach) or regular classes annotated with the @Aspect annotation (the @AspectJ style).

  • Join point: A point during the execution of a program, such as the execution of a method or the handling of an exception. In Spring AOP, a join point always represents a method execution.

  • Advice: Action taken by an aspect at a particular join point. Different types of advice include “around”, “before” and “after” advice. (Advice types are discussed later.) Many AOP frameworks, including Spring, model an advice as an interceptor and maintain a chain of interceptors around the join point.

  • Pointcut: A predicate that matches join points. Advice is associated with a pointcut expression and runs at any join point matched by the pointcut (for example, the execution of a method with a certain name). The concept of join points as matched by pointcut expressions is central to AOP, and Spring uses the AspectJ pointcut expression language by default.

  • Introduction: Declaring additional methods or fields on behalf of a type. Spring AOP lets you introduce new interfaces (and a corresponding implementation) to any advised object. For example, you could use an introduction to make a bean implement an IsModified interface, to simplify caching. (An introduction is known as an inter-type declaration in the AspectJ community.)

  • Target object: An object being advised by one or more aspects. Also referred to as the “advised object”. Since Spring AOP is implemented by using runtime proxies, this object is always a proxied object.

  • AOP proxy: An object created by the AOP framework in order to implement the aspect contracts (advise method executions and so on). In the Spring Framework, an AOP proxy is a JDK dynamic proxy or a CGLIB proxy.

  • Weaving: linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), load time, or at runtime. Spring AOP, like other pure Java AOP frameworks, performs weaving at runtime.

Spring AOP includes the following types of advice:

  • Before advice: Advice that runs before a join point but that does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception).

  • After returning advice: Advice to be run after a join point completes normally (for example, if a method returns without throwing an exception).

  • After throwing advice: Advice to be executed if a method exits by throwing an exception.

  • After (finally) advice: Advice to be executed regardless of the means by which a join point exits (normal or exceptional return).

  • Around advice: Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice. Around advice can perform custom behavior before and after the method invocation. It is also responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception.

相关文章:

读spring官方文档的一些关键知识点介绍

目录 bean definitionBeanPostProcessorBeanFactoryPostProcessorComponent and Further Stereotype AnnotationsAOP Concepts bean definition https://docs.spring.io/spring-framework/docs/5.1.3.RELEASE/spring-framework-reference/core.html#beans-child-bean-definiti…...

2024年AI与大数据技术趋势洞察:跨领域创新与社会变革

目录 引言 技术洞察 1. 大模型技术的创新与开源推动 2. AI Agent 智能体平台技术 3. 多模态技术的兴起:跨领域应用的新风口 4. 强化学习与推荐系统:智能化决策的底层驱动 5. 开源工具与平台的快速发展:赋能技术创新 6. 技术安全与伦理:AI技术的双刃剑 7. 跨领域技…...

ThinkPhp项目解决静态资源请求的跨域问题的解决思路

背景&#xff1a;我在前端使用vue语言开发的&#xff0c;请求的后端是用ThinkPhp项目开发的。我vue项目里的请求php接口&#xff0c;自带header参数的跨域问题通过网上查询到的server端配置方法已经解决了。我使用的 是中间件的配置方法&#xff1a; <?php//admin 项目 配…...

mybatis的多对一、一对多的用法

目录 1、使用VO聚合对象&#xff08;可以解决这两种情况&#xff09; 多对一&#xff1a; 一对多&#xff1a; 2、非聚合的多对一做法&#xff1a; 3、非聚合的一对多做法&#xff1a; 1、使用VO聚合对象&#xff08;可以解决这两种情况&#xff09; 当我需要多对一、一对…...

消息队列实战指南:三大MQ 与 Kafka 适用场景全解析

前言&#xff1a;在当今数字化时代&#xff0c;分布式系统和大数据处理变得愈发普遍&#xff0c;消息队列作为其中的关键组件&#xff0c;承担着系统解耦、异步通信、流量削峰等重要职责。ActiveMQ、RabbitMQ、RocketMQ 和 Kafka 作为市场上极具代表性的消息队列产品&#xff0…...

前端发送Ajax请求的技术Axios

目录 1.引入Axios文件 2.使用Axios发送请求 2.1请求方法的别名 请求的URL地址怎么来的&#xff1f; 后端实现 前后端交互 1.引入Axios文件 <script src"https://unpkg.com/axios/dist/axios.min.js"></script> 2.使用Axios发送请求 2.1请求方法的…...

第17章:Python TDD回顾与总结货币类开发

写在前面 这本书是我们老板推荐过的&#xff0c;我在《价值心法》的推荐书单里也看到了它。用了一段时间 Cursor 软件后&#xff0c;我突然思考&#xff0c;对于测试开发工程师来说&#xff0c;什么才更有价值呢&#xff1f;如何让 AI 工具更好地辅助自己写代码&#xff0c;或许…...

opencv_KDTree_搜索介绍及示例

cv::flann::KDTreeIndexParams 说明&#xff0c;使用&#xff1f; cv::flann::KDTreeIndexParams 是 OpenCV 中用于配置 KD 树&#xff08;K-Dimensional Tree&#xff09;索引参数的类。KD 树是一种用于多维空间中的点搜索的数据结构&#xff0c;常用于最近邻搜索等问题。在…...

Windows 上安装 MongoDB 的 zip 包

博主介绍&#xff1a; 大家好&#xff0c;我是想成为Super的Yuperman&#xff0c;互联网宇宙厂经验&#xff0c;17年医疗健康行业的码拉松奔跑者&#xff0c;曾担任技术专家、架构师、研发总监负责和主导多个应用架构。 近期专注&#xff1a; RPA应用研究&#xff0c;主流厂商产…...

先进制造aps专题二十七 西门子opcenter aps架构分析

欧美的商业aps&#xff0c;主要就是sap apo,西门子opcenter aps,达索quintiq 从技术的层面&#xff0c;西门子aps是不如sap apo的&#xff0c;但是西门子aps是西门子数字化工厂产品的核心&#xff0c;有很多特色&#xff0c;所以分析 西门子aps主要分计划器和排产器两个部分 计…...

【数据分享】1929-2024年全球站点的逐年平均气温数据(Shp\Excel\无需转发)

气象数据是在各项研究中都经常使用的数据&#xff0c;气象指标包括气温、风速、降水、湿度等指标&#xff0c;其中又以气温指标最为常用&#xff01;说到气温数据&#xff0c;最详细的气温数据是具体到气象监测站点的气温数据&#xff01;本次我们为大家带来的就是具体到气象监…...

机器学习——什么是代价函数?

1.代价函数的定义 首先,提到代价函数是估计值和实际值的差,这应该是指预测值和真实值之间的差异,用来衡量模型的好坏。 在一元线性模型中,模型是直线,有两个参数,可能是斜率和截距。 通过调整这两个参数,让代价函数最小,这应该是说我们要找到最佳的斜率和截距,使得预测…...

docker 部署 MantisBT

1. docker 安装MantisBT docker pull vimagick/mantisbt:latest 2.先运行实例&#xff0c;复制配置文件 docker run -p 8084:80 --name mantisbt -d vimagick/mantisbt:latest 3. 复制所需要配置文件到本地路径 docker cp mantisbt:/var/www/html/config/config_inc.php.…...

02内存结构篇(D1_自动内存管理)

目录 一、内存管理 1. C/C程序员 2. Java程序员 二、运行时数据区 1. 程序计数器 2. Java虚拟机栈 3. 本地方法栈 4. Java堆 5. 方法区 运行时常量池 三、Hotspot运行时数据区 四、分配JVM内存空间 分配堆的大小 分配方法区的大小 分配线程空间的大小 一、内存管…...

Centos 8 交换空间管理

新增swap 要增加 Linux 系统的交换空间&#xff0c;可以按照以下步骤操作&#xff1a; 1. 创建一个交换文件 首先&#xff0c;选择文件路径和大小&#xff08;例如&#xff0c;增加 1 GB 交换空间&#xff09;。 sudo fallocate -l 1G /swapfile如果 fallocate 不可用&…...

“深入浅出”系列之数通篇:(5)TCP的三次握手和四次挥手

TCP&#xff08;传输控制协议&#xff09;的三次握手和四次挥手是TCP连接建立和释放的过程。 一、TCP三次握手 TCP三次握手是为了建立可靠的连接&#xff0c;确保客户端和服务器之间的通信能力。具体过程如下&#xff1a; 第一次握手&#xff1a;客户端向服务器发送一个带有…...

接口测试及接口测试常用的工具

&#x1f345; 点击文末小卡片&#xff0c;免费获取软件测试全套资料&#xff0c;资料在手&#xff0c;涨薪更快 首先&#xff0c;什么是接口呢&#xff1f; 接口一般来说有两种&#xff0c;一种是程序内部的接口&#xff0c;一种是系统对外的接口。 系统对外的接口&#xff…...

使用rpc绕过咸鱼sign校验

案例网站是咸鱼 找到加密函数i()&#xff0c;发现参数是由token时间戳appkeydata构成的 js客户端服务 考虑到网站可能有判断时间戳长短而让请求包失效的可能&#xff0c;我们请求包就直接用它的方法生成 下面我们先把token和h置为键值对tjh123 再把方法i()设为全局变量my_…...

NPC与AI深度融合结合雷鸟X3Pro AR智能眼镜:引领游戏行业沉浸式与增强现实新纪元的畅想

if… NPC&#xff08;非玩家角色&#xff09;与AI&#xff08;人工智能&#xff09;的深度融合&#xff0c;正引领游戏行业迈向一个全新的沉浸式与增强现实&#xff08;AR&#xff09;相结合的新时代。这一创新不仅预示着游戏体验的质变&#xff0c;更可能全面革新游戏设计与叙…...

【物联网】ARM核介绍

文章目录 一、芯片产业链1. CPU核(1)ARM(2)MIPS(3)PowerPc(4)Intel(5)RISC-V 2. SOC芯片(1)主流厂家(2)产品解决方案 3. 产品 二、ARM核发展1. 不同架构的特点分析(1)VFP(2)Jazelle(3)Thumb(4)TrustZone(5)SIMD(6)NEON 三、ARM核(ARMv7)工作模式1. 权限级别(privilege level)2.…...

Americhem于Chinaplas 2026宣布在华新增投资,进一步拓展其全球医疗健康业务版图

全球领先的高分子材料解决方案提供商Americhem今日宣布&#xff0c;通过在中国苏州新建一座洁净复合材料生产设施&#xff0c;进一步强化其在医疗健康领域的能力&#xff1b;同时&#xff0c;公司还将在Chinaplas 2026展会上推出多项先进材料技术。该设施预计将于2026年下半年投…...

从代码工厂到智能协作者:AI原生研发组织变革的5阶跃迁模型(附SITS2026评估矩阵V2.1)

第一章&#xff1a;从代码工厂到智能协作者&#xff1a;AI原生研发组织变革的5阶跃迁模型&#xff08;附SITS2026评估矩阵V2.1&#xff09; 2026奇点智能技术大会(https://ml-summit.org) 传统研发组织正经历一场静默却深刻的范式迁移&#xff1a;代码不再由人单向输出&#…...

蓝桥杯第15届单片机满分

1. 为什么会在第 5 位显示出 8&#xff1f;freq_jiaofreqseg_jiao;//频率数据的最终结果 if(freq_jiao<0) {wrong1;//频率界面数码管显示LL,表示此状态错误 } else wrong0;而在 serviceT1 的中断里&#xff0c;每 1000ms 更新一次 freq&#xff1a;当测试系统改变输入频率&a…...

ECAPA-TDNN说话人识别终极指南:从零开始构建高性能语音验证系统

ECAPA-TDNN说话人识别终极指南&#xff1a;从零开始构建高性能语音验证系统 【免费下载链接】ECAPA-TDNN Unofficial reimplementation of ECAPA-TDNN for speaker recognition (EER0.86 for Vox1_O when train only in Vox2) 项目地址: https://gitcode.com/gh_mirrors/ec/E…...

数论实战:从质因数分解到完全平方数的构造

1. 完全平方数的本质与判定方法 完全平方数就像数学世界里的完美正方形&#xff0c;它们总能被整齐地拆解成两个相同整数的乘积。比如16可以表示为44&#xff0c;25则是55的结果。这种数字在密码学、图像处理和算法优化中都有重要应用&#xff0c;比如在内存对齐优化时&#xf…...

第5篇 | SOA实践启示录:从信号到服务,AUTOSAR的架构跃迁

2025年底&#xff0c;L2级辅助驾驶渗透率已接近60%&#xff0c;汽车正从“功能堆叠”走向“服务化”。AUTOSAR Adaptive平台是这场变革的技术底座。 SOME/IP服务接口详解 SOME/IP将服务接口分为三类&#xff1a; Method&#xff1a;请求-响应式操作&#xff08;如SetTargetTe…...

终极指南:如何用Bitfocus Companion将普通控制器变身高性价比专业控制台

终极指南&#xff1a;如何用Bitfocus Companion将普通控制器变身高性价比专业控制台 【免费下载链接】companion Bitfocus Companion enables the Elgato Stream Deck and other controllers to be a professional shotbox surface for an increasing amount of different pres…...

编写程序实现智能户外帐篷湿检测,内部结露时,提示“通风除湿”。

智能户外帐篷湿度检测系统&#xff1a;从原理到实现一、实际应用场景描述在户外露营场景中&#xff0c;帐篷内部湿度受外界环境&#xff08;如雨天、清晨露水&#xff09;和人体活动&#xff08;呼吸、汗液蒸发&#xff09;影响显著。当帐篷内湿度超过70%时&#xff0c;空气中的…...

D3KeyHelper终极指南:5步轻松掌握暗黑3智能按键操作

D3KeyHelper终极指南&#xff1a;5步轻松掌握暗黑3智能按键操作 【免费下载链接】D3keyHelper D3KeyHelper是一个有图形界面&#xff0c;可自定义配置的暗黑3鼠标宏工具。 项目地址: https://gitcode.com/gh_mirrors/d3/D3keyHelper 你是否在暗黑破坏神3的高强度战斗中感…...

用Python+海康MV-CH120-60UM相机实现条形码识别,从硬件连接到代码调试的完整避坑指南

Python海康MV-CH120-60UM工业相机条形码识别实战&#xff1a;从硬件配置到智能解码的完整解决方案 工业视觉领域的开发者们常常面临一个现实问题&#xff1a;如何快速将硬件设备与软件系统无缝对接&#xff1f;本文将以海康威视MV-CH120-60UM工业相机为例&#xff0c;手把手带你…...