applicationContext.xml
<?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
http://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></context:annotation-config>
</beans>


autowire
byName

byType

·
使用注解实现自动装配

@Autowired


直接在属性上用,或在set上用
使用Autowired我们可以不用编写set方法了,前提是你这个自动装配的属性在IOC(spring)容器中存在,
且符合名字byname!
科普
@Nullable 字段标记了这个注解,说明这个字段可以为null;


如果@Autowired自动装配的环境比较复制,自动装配无法通过一个注解【@Autowired】完成的时候,
我们可以使用 @Qualifier(value = "xxx") 去配合@Autowired使用,指定一个唯一的bean对象注入

@Resourse
先通过名字查找,再通过类型查找。
可以@Resourse(name = “xxx”)



浙公网安备 33010602011771号