Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring FileNotFoundException_Spring_Filenotfoundexception - Fatal编程技术网

Spring FileNotFoundException

Spring FileNotFoundException,spring,filenotfoundexception,Spring,Filenotfoundexception,我为学习Spring编写了以下两个Java类,但在运行代码后获得FileNotFoundException。请帮我解决这个问题 它不是采用XML文件的路径吗 package com.javatpoint; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Te

我为学习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();  
  }
}  
(二)

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>  


您在哪里定义了xmlContext.xml?那个位置在类路径中吗?我想xmlContext.xml不在类路径位置中?您可以添加相对路径或绝对路径来获取此固定路径。xmlConext.xml存在于同一com.javatpoint包中。您在哪里定义了xmlContext.xml?那个位置在类路径中吗?我想xmlContext.xml不在类路径位置中?您可以添加相对路径或绝对路径来获取此fixed.xmlConext.xml在同一com.javatpoint包中
<?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>