maven项目的系统根目录默认是src/main/java和src/main/resources,而不是src,所以beans.xml文件必须放到src/main/java和src/main/resources下面的文件夹或者包中,否则就会报上面的错误:java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exit.
开启注解扫描
<?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">
<!-- 开启注解扫描 (1)到包中扫描类、方法、属性上是否有注解 -->
<context:component-scan base-package="com.wm103"></context:component-scan>
<!-- (2)只扫描属性上的注解 -->
<!--<context:annotation-config></context:annotation-config>-->
</beans>