1、如果项目全程使用Spring注解来完成依赖注入,则需要在Spring基本配置文件中声明注解解释器,配置注解扫描包路径
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" ... xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd ... <context:annotation-config/> <!-- 使用该配置上条配置可省略 --> <context:component-scan base-package="com.meng"/> </beans>