1.要使用Spring的自动扫描的这样一个组件,要在spring中的配置文件中这样做:
<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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
我在
xsi:schemaLocation中漏加了后面两句
2.我把web.xml移到了WEB-INF的外边去了,导致出现http404错误,比较粗心
3.就是ClassPathXmlApplicationContext只可以读取web-info/classes目录下的配置文件,而且不能是绝对路径.使用 cxt = new ClassPathXmlApplicationContext("beans.xml");而不是 cxt = new ClassPathXmlApplicationContext(Constants.APPLICATION_PATH+"beans.xml");