自动扫描
程序自动注入属性,得到对象,适用基本类型
-
配置文件
<?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 http://www.springframework.org/schema/context/spring-context.xsd"> <!--指定注解扫描包--> <context:component-scan base-package="com.xxx"/> <context:annotation-config></context:annotation-config> </beans>
-
注入对象前面添加注释@Component/Controller/Service/Repository
-
注入对象的属性前面添加@Value(“舒畅”)
-
其他什么都不用写。包括set方法,bean标签
思考:重点掌握xml那套,后面的自动装配,自动扫描,有个印象,后面用再说