注解开发必须导入配置文件,注解卡法不必导入set配置
官网地址:
https://docs.spring.io/spring-framework/docs/5.3.10-SNAPSHOT/reference/html/core.html#beans-annotation-config
配置文件:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config/> </beans>
Autowired注解开发:先使用ByType方法通过类class查找,如果找不到再通过ByName用id查找
required() 设置内容是否为能空
@Qualifier(value=" ")可以指定特定了bean,效果和Autowired效果相同
Resource注解卡法:先使用ByName方法通过id查找,如果找不到再通过ByType用class查找