applicationContext需要配置 <context:annotation-config/>吗
来源:5-8 元数据注解
程序员叶某
2022-09-27 11:56:30
spring官方文档中加入了
<?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>
但是课程中没有加入
<context:annotation-config/>
这句话也能使用注解,请问这句话是干什么的,有必要添加吗
1回答
好帮手慕小脸
2022-09-27
同学你好,
1、<context:annotation-config/>的作用:它是对已注册过的Bean的进行操作的配置,也就是说,Bean已经通过某种方式(比如Xml配置)被注册,然后使用这个配置。
2、<context:component-scan />的作用:<context:component-scan />和<context:annotation-config/>一样的作用,另外它还可以扫描指定包下的类,将拥有注解的类注册到Spring中,因此当使用<context:component-scan/>后,即可将<context:annotation-config/>省去。
祝学习愉快~
相似问题
回答 1
回答 1