Spring 3.0 中bean.xml文件的配置问题

    刚开始系统的学习Spring,按照其教程试着尝试实例化IOC容器,了解下Spring的基本原理。

实例化Spring IOC容器的简单方法:

(1).方法1:

//如果只有一个spring配置文件也可以直接传递一个string参数,不需要使用数组
ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{“spring配置文件路径”});

(2).方法2:

Resource res = new FileSystemResource(“spring配置文件”);
BeanFactory factory = new XMLBeanFactory(res);


但是在bean-xml的配置文件上遇到了如下的错误:

   og4j:WARN No appenders could be found for logger (org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from file [D:\Myeclipse 9.0\Spring\bean.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.

提示找不到元素beans 的声明,查找后发现应该是xml文件配置问题

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
<description>Spring Quick Start</description>
<bean id="TheAction"
class="net.zk.spring.learn.LowerAction">
<property name="message">
<value>HeLLo</value>
</property>
</bean>
</beans>

最终修改配置好一切正常,需要说明的是xmlns对spring版本有严格要求,这里使用的是spring3.0版本。出现问题时,需要按版本自行修改。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值