Spring FileNotFoundException
我为学习Spring编写了以下两个Java类,但在运行代码后获得FileNotFoundException。请帮我解决这个问题 它不是采用XML文件的路径吗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
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>