同步操作将从 turnon/blog 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
title: Spring 配置元数据
date: 2022-12-21 19:49:48
categories:
- Java
- 框架
- Spring
- Spring核心
tags:
- Java
- 框架
- Spring
- Bean
permalink: /pages/55f315/
Bean 配置元信息 - BeanDefinition
Spring XML 配置元信息 - beans 元素相关
beans 元素属性 | 默认值 | 使用场景 |
---|---|---|
profile | null(留空) | Spring Profiles 配置值 |
default-lazy-init | default | 当 outter beans “default-lazy-init” 属性存在时,继承该值,否则为“false” |
default-merge | default | 当 outter beans “default-merge” 属性存在时,继承该值,否则为“false” |
default-autowire | default | 当 outter beans “default-autowire” 属性存在时,继承该值,否则为“no” |
default-autowire-candidates | null(留空) | 默认 Spring Beans 名称 pattern |
default-init-method | null(留空) | 默认 Spring Beans 自定义初始化方法 |
default-destroy-method | null(留空) | 默认 Spring Beans 自定义销毁方法 |
Spring XML 配置元信息 - 应用上下文相关
XML 元素 | 使用场景 |
---|---|
<context:annotation-config /> |
激活 Spring 注解驱动 |
<context:component-scan /> |
Spring @Component 以及自定义注解扫描 |
<context:load-time-weaver /> |
激活 Spring LoadTimeWeaver |
<context:mbean-export /> |
暴露 Spring Beans 作为 JMX Beans |
<context:mbean-server /> |
将当前平台作为 MBeanServer |
<context:property-placeholder /> |
加载外部化配置资源作为 Spring 属性配 |
<context:property-override /> |
利用外部化配置资源覆盖 Spring 属 |
底层实现 - XmlBeanDefinitionReader
XML 元素 | 使用场景 |
---|---|
<beans:beans /> |
单 XML 资源下的多个 Spring Beans 配置 |
<beans:bean /> |
单个 Spring Bean 定义(BeanDefinition)配置 |
<beans:alias /> |
为 Spring Bean 定义(BeanDefinition)映射别名 |
<beans:import /> |
加载外部 Spring XML 配置资源 |
底层实现 - PropertiesBeanDefinitionReader
Properties 属性名 | 使用场景 |
---|---|
class |
Bean 类全称限定名 |
abstract |
是否为抽象的 BeanDefinition |
parent |
指定 parent BeanDefinition 名称 |
lazy-init |
是否为延迟初始化 |
ref |
引用其他 Bean 的名称 |
scope |
设置 Bean 的 scope 属性 |
${n} | n 表示第 n+1 个构造器参数 |
Spring 模式注解
Spring 注解 | 场景说明 | 起始版本 |
---|---|---|
@Repository |
数据仓储模式注解 | 2.0 |
@Component |
通用组件模式注解 | 2.5 |
@Service |
服务模式注解 | 2.5 |
@Controller |
Web 控制器模式注解 | 2.5 |
@Configuration |
配置类模式注解 | 3.0 |
Spring Bean 定义注解
| Spring 注解 | 场景说明 | 起始版本 |
| ------------ | ------------------------------------------ | ----------- | --- |
| @Bean
| 替换 XML 元素 <bean>
| 3.0 |
| @DependsOn
| 替代 XML 属性 <bean depends-on="..."/>
| 3.0 |
| @Lazy
| 替代 XML 属性 <bean lazy-init="true | falses" />
| 3.0 |
| @Primary
| 替换 XML 元素 <bean primary="true | false" />
| 3.0 |
| @Role
| 替换 XML 元素 <bean role="..." />
| 3.1 |
| @Lookup
| 替代 XML 属性 <bean lookup-method="...">
| 4.1 |
Spring Bean 依赖注入注解
Spring 注解 | 场景说明 | 起始版本 |
---|---|---|
@Autowired |
Bean 依赖注入,支持多种依赖查找方式 | 2.5 |
@Qualifier |
细粒度的 @Autowired 依赖查找 | 2.5 |
Java 注解 | 场景说明 | 起始版本 |
---|---|---|
@Resource | 类似于 @Autowired | 2.5 |
@Inject | 类似于 @Autowired | 2.5 |
Spring Bean 条件装配注解
Spring 注解 | 场景说明 | 起始版本 |
---|---|---|
@Profile | 配置化条件装配 | 3.1 |
@Conditional | 编程条件装配 | 4.0 |
Spring Bean 生命周期回调注解
Spring 注解 | 场景说明 | 起始版本 |
---|---|---|
@PostConstruct | 替换 XML 元素 或 InitializingBean | 2.5 |
@PreDestroy | 替换 XML 元素 或 DisposableBean | 2.5 |
Spring BeanDefinition 解析与注册
Spring 注解 | 场景说明 | 起始版本 |
---|---|---|
XML 资源 | XmlBeanDefinitionReader | 1.0 |
Properties 资源 | PropertiesBeanDefinitionReader | 1.0 |
Java 注解 | AnnotatedBeanDefinitionReader | 3.0 |
核心 API - XmlBeanDefinitionReader
核心 API - PropertiesBeanDefinitionReader
核心 API - AnnotatedBeanDefinitionReader
Spring IoC 容器相关 XML 配置
命名空间 | 所属模块 | Schema 资源 URL |
---|---|---|
beans | spring-beans | https://www.springframework.org/schema/beans/spring-beans.xsd |
context | spring-context | https://www.springframework.org/schema/context/spring-context.xsd |
aop | spring-aop | https://www.springframework.org/schema/aop/spring-aop.xsd |
tx | spring-tx | https://www.springframework.org/schema/tx/spring-tx.xsd |
util | spring-beans | beans https://www.springframework.org/schema/util/spring-util.xsd |
tool | spring-beans | https://www.springframework.org/schema/tool/spring-tool.xsd |
Spring IoC 容器装配注解
Spring 注解 | 场景说明 | 起始版本 |
---|---|---|
@ImportResource | 替换 XML 元素 <import>
|
3.0 |
@Import | 导入 Configuration Class | 3.0 |
@ComponentScan | 扫描指定 package 下标注 Spring 模式注解的类 | 3.1 |
Spring IoC 配属属性注解
Spring 注解 | 场景说明 | 起始版本 |
---|---|---|
@PropertySource | 配置属性抽象 PropertySource 注解 | 3.1 |
@PropertySources | @PropertySource 集合注解 | 4.0 |
Spring XML 扩展
BeanDefinitionParserDelegate#parseCustomElement(org.w3c.dom.Element, BeanDefinition)
注解驱动
API 编程
API 编程
Spring 內建 XML Schema 常见有哪些?
命名空间 | 所属模块 | Schema 资源 URL |
---|---|---|
beans | spring-beans | https://www.springframework.org/schema/beans/spring-beans.xsd |
context | spring-context | https://www.springframework.org/schema/context/spring-context.xsd |
aop | spring-aop | https://www.springframework.org/schema/aop/spring-aop.xsd |
tx | spring-tx | https://www.springframework.org/schema/tx/spring-tx.xsd |
util | spring-beans | beans https://www.springframework.org/schema/util/spring-util.xsd |
tool | spring-beans | https://www.springframework.org/schema/tool/spring-tool.xsd |
Spring 配置元信息具体有哪些?
Extensible XML authoring 的缺点?
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。