Spring Core Technologies

Spring Core Technologies

简介

记录一些核心功能以及接口 在spring官方文档的中的位置,便于后期查找

https://docs.spring.io/spring-framework/docs/current/reference/html/core.html

v.5.3.14

1. IoC Container

1.6.1 生命周期回调 重点

1.6.2 aware接口

例子:beanNameAware

1.8.1 BeanPostProcessor

​ example AutowiredAnnotationBeanPostProcessor
​ AutowiredAnnotationBeanPostProcessor一个BeanPostProcessor随 Spring 发行版一起提供的实现,并自动装配带注释的字段、setter 方法和任意配置方法。

1.8.2 BeanFactoryPostProcessor 后置处理器

PropertySourcesPlaceholderConfigurer 用于替换占位符,用到了访问者模式 interesting

1.8.3 FactoryBean 自定义实例化逻辑

When you need to ask a container for an actual FactoryBean instance itself instead of the bean it produces, prefix the bean’s id with the ampersand symbol (&) when calling the getBean() method of the ApplicationContext. So, for a given FactoryBean with an id of myBean, invoking getBean("myBean") on the container returns the product of the FactoryBean, whereas invoking getBean("&myBean") returns the FactoryBean instance itself.

1.9.1 注解支持

<context:annotation-config/>

​ 从Spring Framework 5.1 开始,@Required注解 和RequiredAnnotationBeanPostProcessor正式弃用,赞成使用构造函数注入进行所需的设置(或自定义实现InitializingBean.afterPropertiesSet() 或自定义@PostConstruct方法以及 bean 属性设置方法)。

1.10.1 组件扫描

<context:component-scan base-package="org.example"/> <context:component-scan>隐式启用 <context:annotation-config>. <context:annotation-config>使用时通常不需要包含 元素<context:component-scan>

1.12. 基于 Java 的容器配置

基本概念:@Bean和@Configuration

使用实例化 Spring 容器 AnnotationConfigApplicationContext 使用@Bean注解 使用@Configuration注释 编写基于 Java 的配置 Bean 定义配置文件 PropertySource 抽象 使用 @PropertySource 语句中的占位符解析

1.12.2 使用实例化 Spring 容器AnnotationConfigApplicationContext

1.12.4 使用@Configuration注释

@Configuration public class AppConfig { @Bean public BeanOne beanOne() { return new BeanOne(beanTwo()); } @Bean public BeanTwo beanTwo() { return new BeanTwo(); } }

这种声明 bean 间依赖关系的@Bean方法仅在该方法在@Configuration类中声明时才有效。您不能使用普通@Component类来声明 bean 间的依赖关系。

1.13 环境接口 该Environment接口是集成在容器中的

1.14 注册一个LoadTimeWeaver 不知道啥意思...

1.15 ApplicationContext 接口功能介绍

1.15.1 国际化使用MessageSource 接口

​ 子实现 ResourceBundleMessageSource

1.15.2. 标准和自定义事件

​ 通过ApplicationEvent 类和ApplicationListener接口提供的

2. 资源

2.3. 内置Resource实现

Spring 包括几个内置的Resource实现:
UrlResource
ClassPathResource
FileSystemResource
PathResource
ServletContextResource
InputStreamResource
ByteArrayResource

2.4. 该ResourceLoader接口

ResourceLoader任何标准中的默认值ApplicationContext实际上都是PathMatchingResourcePatternResolver实现ResourcePatternResolver 接口的实例。ApplicationContext实例本身也是如此,它也实现了ResourcePatternResolver接口并委托给默认的 PathMatchingResourcePatternResolver.

Resource为包含通配符或使用特殊classpath*:资源前缀的资源路径加载一个或多个对象,请考虑将ResourcePatternResolverautowired实例 而不是ResourceLoader.

2.7. bean 依赖 资源

package example; public class MyBean { private Resource template; public setTemplate(Resource template) { this.template = template; } // ... }
<bean id="myBean" class="example.MyBean"> <property name="template" value="some/resource/path/myTemplate.txt"/> </bean>
@Component public class MyBean { private final Resource[] templates; public MyBean(@Value("${templates.path}") Resource[] templates) { this.templates = templates; } // ... }
<bean id="myBean" class="example.MyBean"> <property name="template" value="classpath*:/config/templates/*.txt"/> </bean>

2.8.1. 构建应用上下文

3. 验证、数据绑定和类型转换

3.1. 使用 Spring 的 Validator 接口进行验证

3.4. springboot类型转换 Converter

3.4.4. 应用程序ConversionService接口

3.4.5. 配置一个ConversionService

3.5.1. The Formatter SPI

3.6. 配置全局日期和时间格式

3.7. Java Bean 验证

4. Spring 表达式语言 (SpEL)

public class SPELTest { public static void main(String[] args) { ExpressionParser parser = new SpelExpressionParser(); Expression exp = parser.parseExpression("'Hello World'"); String message = (String) exp.getValue(); System.out.println(message); exp = parser.parseExpression("'Hello World'.concat('!')"); message = (String) exp.getValue(); System.out.println(message); exp = parser.parseExpression("'Hello World'.bytes"); byte[] bytes = (byte[]) exp.getValue(); System.out.println(bytes); exp = parser.parseExpression("'Hello World'.bytes.length"); int length = (Integer) exp.getValue(); System.out.println(length); exp = parser.parseExpression("new String('hello world').toUpperCase()"); message = exp.getValue(String.class); System.out.println(message); } }

4.1.1. 理解EvaluationContext

4.3. 语言参考 表达式使用文档

5. Aspect Oriented Programming with Spring

5.4.1. 启用@AspectJ 支持

还没看源码 .... 目前还不是很理解


__EOF__

本文作者Immortal-mode
本文链接https://www.cnblogs.com/immortal-mode/p/15751791.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   immortal_mode  阅读(60)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示