# Hspring **Repository Path**: wh543/Hspring ## Basic Information - **Project Name**: Hspring - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-04-01 - **Last Updated**: 2022-03-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Spring基础核心模块 spring-core - 包含框架基本的核心工具类 - 定义并提供资源的访问方式 spring-beans:Spring主要面向Bean编程(BOP) - Bean的定义 - Bean的解析 - Bean的创建 spring-context - 为Spring提供运行时环境,保持对象的状态 - 拓展了BeanFactory spring-aop:最小化的动态代理实现 - JDK动态代理 - Cglib - 只能使用运行时织入,仅支持方法级编织,仅支持方法执行切入点 spring-aspectj + spring-instrument = full AspectJ 织入方式: - 编译期Weaving - 类加载期Weaving - 运行期Weaking | Spring AOP | AspectJ | | ------------------------------------------------ | ------------------------------------------------------------ | | 在纯Java中实现 | 使用Java编程语言的扩展实现 | | 不需要单独的编译过程 | 除非设置LTW,否则需要AspectJ编译期(ajc) | | 只能使用运行时织入 | 运行时织入不可用。支持编译时、编译后和加载时织入 | | 功能不强-仅支持方法级编织 | 更强大。可以编织字段、方法、构造函数、静态初始值设定项、最终类/方法等 | | 只能在由Spring容器管理的bean上实现 | 可以在所有域对象上实现 | | 仅支持方法执行切入点 | 支持所有切入点 | | 代理是由目标对象创建的,并且切面应用在这些代理上 | 在执行应用程序之前(在运行时)前,各方面直接在代码中进行织入 | | 比AspectJ慢多了 | 更好的性能 | | 易于学习和应用 | 相对于Spring AOP来说更复杂 | ## 泛型 ### 泛型类 ```java class 类名称<泛型标识:可以随便写任意标识号,标识制定的泛系的类型> { 修饰符 泛型标识 /* 成员变量类型 */ 修饰符 构造函数(泛型标识 参数){ ... } } ``` ```java public abstract class GenericClassExample { /** * member这个成员变量的类型为T,T的类型由外部制定 */ private T member; public GenericClassExample(T member) { this.member = member; } public abstract R handle(T member); } ``` 给泛型加入上边界 `? extend E` 给泛型加入下边界 `? super E` ### 泛型接口 ```java public interface GenericClassExample { public R handle(T member); } ``` ### 泛型方法 ```java public void print(T t) { System.out.println(t); } ``` E - element:在集合中使用 T - Type:java类 K - key:键 V - value:值 N - Number:数值 ## 注解 提供一种为程序元素设置元数据的方法 - 元数据是添加到程序元素如方法、字段、类和包上的额外信息。 - 注解是一种分散式的元数据设置方式,xml是集中式的设置方式 - 注解不能直接干扰程序代码的运行 ![image-20211225232448026](images/image-20211225232448026.png) 功能 - 作为特定的标记,用于告诉编译器一些信息 - 编译时动态处理,如动态生成代码,如lombox - 运行时动态处理,作为额外信息的载体,如获取注解信息 分类 - 标准注解:@Override、@Deprecated、@SuppressWarnings - 元注解:@Retention、@Target、@Inherited、@Documented - 自定义注解 元注解 用于修饰注解的注解,通常用在注解的定义上 - @Target:注解的作用目标 描述所修饰的注解的使用范围 - packages、type(类、接口、枚举、Annotation类型) - 类型成员(方法、构造方法、成员变量、枚举值) - 方法参数和本地变量(如循环变量、catch参数) - @Retention:注解的生命周期 标注注解被保留时间的长短 - 用于定义注解的生命周期 - SOURCE (Annotations are to be discarded by the compiler.) - CLASS (Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time. This is the default behavior.) - RUNTIME (Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.) - @Documented:注解是否应当被包含在JavaDoc文档中 - @Inherited:是否允许子类继承该注解 自定义注解 自定义注解的格式 ```java public @interface 注解名 { 修饰符 返回值 属性名() 默认值; ... } ``` 反射相关类与注解的关系 Class 实现了 AnnotatedElement Constructor 继承了 Excutable,Excutable 继承了 AccessibleObject,AccessibleObject 实现了 AnnotatedElement Method 继承了 Executable Field 继承了 AnnotatedElement ![image-20211226102525305](images/image-20211226102525305.png)