@Autowired设置默认值
时间: 2023-10-07 15:09:18 浏览: 84
回答: @Autowired注解的默认值是required=true,即默认情况下,如果没有匹配到对应的类,会报错。\[2\]如果想要设置默认值为false,可以在@Autowired注解上添加required=false的属性值。这样,在没有匹配到对应的类时,不会报错,而是会将该属性设置为null。\[2\]
#### 引用[.reference_title]
- *1* *3* [Spring @Autowired 用法](https://blog.csdn.net/qq_29025955/article/details/128718490)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [spring @Autowired使用详解](https://blog.csdn.net/mengyuanye/article/details/116562197)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文