`
baoxiaofei
  • 浏览: 32122 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

郁闷了,一个最简单的Spring小程序都没搞定

阅读更多
今天 按照网上的例子 自己敲了一下代码 想学习一下Spring 但是 无论怎么弄 那个applicationContext.xml就是加载不进去 郁闷死我了
我的小例子:
<?xml version="1.0" encoding="UTF-8"?>
<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 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="helloBean" class="com.baoxiaofei.MySpring.HelloBeanZH" />
<bean id="messageBean" class="com.baoxiaofei.MySpring.MessageBean">
  <property name="hello" ref="helloBean"></property>
</bean>
</beans>

测试代码如下:
package com.baoxiaofei.MySpring;

import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class TestMessageBean {
@Test
public void test2(){
//     String[] config = {"applicationContext.xml"};
//     ApplicationContext ac = new
                     ClassPathXmlApplicationContext(config);
    ApplicationContext ac = new 
                     FileSystemXmlApplicationContext("E:\\mywork\\myPro\\SpringTest\\src\\applicationContext.xml");
// boolean b = ac.containsBean("messageBean");
// String config1 = "/src/applicationContext.xml";
// Resource cr = new ClassPathResource(config1);
// BeanFactory ac = new XmlBeanFactory(cr);
MessageBean message = (MessageBean)ac.getBean("messageBean");
message.show();
}

}

上面加载的方式都试过了,就是不行
每次运行的时候 只会打印:
2012-4-26 23:14:43 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@1888759: startup date [Thu Apr 26 23:14:43 CST 2012]; root of context hierarchy

之后就没有了
这是为什么呢???
盼高人求解!!!
PS:
在同事电脑上和公司电脑上,都可以正常加载这个配置文件,为什么在自己家里就是不行呢?
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics