首先,需要导入注解的约束。(用配置文件其它的部分,拿来修改一下就可以了)
xmlns:context="http://www.springframework.org/schema/context"
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd
第二,开启注解。
<!--开启注解驱动-->
<context:annotation-config/>
第三,指定要扫描的包。
<!--指定要扫描的包-->
<context:component-scan base-package="com.huchuan.pojo"/>
这样就可以使用注解来注入bean了。