当前位置:网站首页>@Autowired注解 required属性
@Autowired注解 required属性
2022-07-25 23:06:00 【qq_42582773】
在@Autowired注解中,有一个required属性,默认为true
@Target({
ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Autowired {
/** * Declares whether the annotated dependency is required. * <p>Defaults to {@code true}. */
boolean required() default true;
}
结论:
- 当required属性为true的时候,注入SpringBean的时候,该bean必须存在,不然会注入失败,启动报错
- 当required属性为false的时候,注入SpringBean的时候,如果bean存在,就注入;如果不存在,就忽略跳过,启动不会报错,但不能直接使用
边栏推荐
- QT Chinese programming encounters c2001 error, prompting "there is a newline character in the constant"
- Week 2: convolutional neural network
- Basic knowledge of radar
- Simulink学习笔记(三)——Simulink自动代码生成(二)「建议收藏」
- Rental experience post
- CUDA environment construction
- Similarities and differences between equals and "= ="
- Hj7 take approximate value
- 5 ROS仿真建模(3- rviz+gazebo+控制仿真机器人)
- Recommend short videos every week: more and more smart devices need collaboration, posing a greater challenge to the development of the Internet of things?
猜你喜欢
随机推荐
Kibana~ the process number cannot be found after kibana is started in the background
What is the difference between bio, NiO and AIO?
Network Security Learning (XIV) IP protocol
[interface performance optimization] reasons for index failure and how to optimize SQL
Network Security Learning (11) scanning and blasting
ZCMU--5015: 完成任务
Longitude and latitude and its transformation with coordinate system
Anaconda installation tutorial environment variables (how to configure environment variables)
Sichuan cuisine menu (I)
Anaconda~Upload did not complete.
MySQL data type
Vs2017 compilation encountered the error HResult e returned by the call of COM component_ FAIL
The third experiment OSPF
技术美术百人计划学习笔记(2)--向量
The difference between "= =" and equals
内存分页与调优,内核与用户空间
为啥谷歌的内部工具不适合你?
How painful is it to write unit tests?
What are the differences between FileInputStream and bufferedinputstream?
The difference between abstract classes and interfaces









