Spring FileNotFoundException

时间:2016-01-06 14:33:58

标签: spring filenotfoundexception

我在下面编写了2个用于学习Spring的Java类,但在运行代码后得到了FileNotFoundException。请帮我解决这个问题。

它没有采用XML文件的路径吗?

package com.javatpoint;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {  
  public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("xmlContext.xml");
    //Resource resource=new ClassPathResource("xmlContext.xml");  
    //BeanFactory factory=new XmlBeanFactory(resource);  

    Student student = (Student)context.getBean("studentbean");  
    student.displayName();  
  }
}  

2)

package com.javatpoint;

public class Student {
  private String name;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public void displayName() {
    System.out.println("Name :"+name);
  }
}

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"  
    xmlns:p="http://www.springframework.org/schema/p"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">  

<bean id="studentbean" class="com.javatpoint.Student">  
  <property name="name" value="Vimal Jaiswal"></property>  
</bean>  

</beans>  

0 个答案:

没有答案