原因:java.io.FileNotFoundException:无法打开ServletContext资源[/applicationContext.xml]
我试图通过使用spring hibernatetemplate将我的hibernate示例移植到spring,但是我得到了这个错误,原因是:java.io.FileNotFoundException:无法打开ServletContext资源[/applicationContext.xml]。请建议我运行我的项目。我在公司里是新手 我的web.xml文件原因:java.io.FileNotFoundException:无法打开ServletContext资源[/applicationContext.xml],java,hibernate,io,struts,filenotfoundexception,Java,Hibernate,Io,Struts,Filenotfoundexception,我试图通过使用spring hibernatetemplate将我的hibernate示例移植到spring,但是我得到了这个错误,原因是:java.io.FileNotFoundException:无法打开ServletContext资源[/applicationContext.xml]。请建议我运行我的项目。我在公司里是新手 我的web.xml文件 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5"
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>applicationContext.xml</param-value>
</context-param>
</web-app>
MY HrMain.java文件->
package login;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class HrMain {
public static void main(String[] args) {
Resource resource = new ClassPathResource("applicationContext.xml");
BeanFactory factory = new XmlBeanFactory(resource);
HrDao dao = (HrDao) factory.getBean("d");
HrModel student = new HrModel();
student.setEmployee_Name("Akash");
student.setPassword("jaisiaram");
dao.saveStudent(student);
}
}
最后,我的查看页面->
<html>
<head>
<title></title>
</head>
<body>
<form action="HrMain" method="post">
<input type="text" name="Employee_Name"/>
<input type="text" name="password">
<input type="submit">
</form>
</body>
</html>
您的
应用程序上下文.xml在哪里?您可以在web.xml
中引用您的applicationContext.xml
,如下所示:
上下文配置位置
/WEB-INF/applicationContext.xml
您的应用程序上下文.xml在哪里?您可以在web.xml
中引用您的applicationContext.xml
,如下所示:
上下文配置位置
/WEB-INF/applicationContext.xml
您的应用程序上下文.xml在哪里?您可以在web.xml
中引用您的applicationContext.xml
,如下所示:
上下文配置位置
/WEB-INF/applicationContext.xml
您的应用程序上下文.xml在哪里?您可以在web.xml
中引用您的applicationContext.xml
,如下所示:
上下文配置位置
/WEB-INF/applicationContext.xml
applicationContext.xml代码粘贴在此页面顶部的第二个位置。您可以将您的applicationContext.xml放入src\main\webapp\WEB-INF中,并参考上面所示的applicationContext.xml代码粘贴在此页面顶部的第二个位置。您可以将您的applicationContext.xml放入src\main\webapp\WEB-INF中,并参考applicationContext.xml如上所示applicationContext.xml代码粘贴在此页面顶部的第二个位置。您可以将您的applicationContext.xml放入src\main\webapp\WEB-INF中,并参考如上所示的applicationContext.xml。applicationContext.xml代码粘贴在此页面顶部的第二个位置您可以将您的applicationContext.xml放入src\main\webapp\WEB-INF并参考上面显示的applicationContext.xml
package login;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class HrMain {
public static void main(String[] args) {
Resource resource = new ClassPathResource("applicationContext.xml");
BeanFactory factory = new XmlBeanFactory(resource);
HrDao dao = (HrDao) factory.getBean("d");
HrModel student = new HrModel();
student.setEmployee_Name("Akash");
student.setPassword("jaisiaram");
dao.saveStudent(student);
}
}
<html>
<head>
<title></title>
</head>
<body>
<form action="HrMain" method="post">
<input type="text" name="Employee_Name"/>
<input type="text" name="password">
<input type="submit">
</form>
</body>
</html>