java.net.MalformedURLException: unknown protocol: classpath


对于刚上手开始练习spring开发框架的人(比如我这样的菜*)来说,也许编写bean.xml也是一个问题,根据夏昕老师的spring开发指南练习入手是个不错的选择。

尝试了一下,配置bean倒是没有什么问题,可只在bean.xml中写个bean是不够的,甚至连基础都没有搭建起来。编译时报错误:
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.

百度了一下,原来还需要在文件的顶头处添加beans标签的定义:
<Beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       classpath:/org/springframework/beans/factory/xml/spring-beans-2.0.xsd
       http://www.springframework.org/schema/context
       classpath:/org/springframework/context/config/spring-context-2.0.xsd"
       default-lazy-init="true">
(原帖:http://llyzq.iteye.com/blog/1117288)
【注:这个标签是最外层的。】

编译通过,运行成功。  特拿来分享一下,以期望与我同样遭遇的人能够快速解决问题。

不过还有一个遗留的错误,就是beans中的classpath配置的问题:
java.net.MalformedURLException: unknown protocol: classpath

虽然不影响运行(错误提示是黑色字体的,不像以前严重的错误时红色的),但还是期望能得到解决,至今未果 ~~~~ ^^^^^^ ~~~~

猜你喜欢

转载自yzwbevin-126-com.iteye.com/blog/1593879
今日推荐