Spring(十):注解实现自动装配
上一篇文章我们已经学习了Bean的自动装配,是在xml文件中配置autowire来实现的,现在我们来学习一下通过注解来实现自动装配。
一、使用注解需要的准备工作
使用注解在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
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>


