1.使用@Controller等的自动注解后需要在配置文件中加入扫描包路径
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<!--
自动递归扫描包
扫描所有加了@Controller/@Service/@Repository/@Component这四种注解之一的类,
以首字母小写的类名称作为键,创建对象作为值,保存到Spring容器中(Map集合)
-->
<context:component-scan base-package="cn.itsource._03_DI_annotation" />
<!-- 开启Spring的注解驱动(它默认就是已经开启的) -->
<context:annotation-config />
<bean id="userService02" class="cn.itsource._03_DI_annotation.service.impl.UserServiceImpl">
</bean>
</beans>