导致:java.io.FileNotFoundException:无法打开ServletContext资源[/applicationContext.xml]

编程入门 行业动态 更新时间:2024-10-26 22:21:36
本文介绍了导致:java.io.FileNotFoundException:无法打开ServletContext资源[/applicationContext.xml]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试通过使用spring hibernatetemplate将我的hibernate示例移植到Spring,但是我得到此错误。导致:java.io.FileNotFoundException:无法打开ServletContext资源[/applicationContext.xml]。请建议我运行我的项目。我更新鲜我的公司

I m trying to port my hibernate example to spring by using spring hibernatetemplate but i m getting this error Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/applicationContext.xml]. Please suggest me run my project. I m fresher in my company

我的web.xml文件

my web.xml file

<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="java.sun/xml/ns/javaee" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="java.sun/xml/ns/javaee java.sun/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>

我的applicationContext.xml

my applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="www.springframework/schema/beans" xmlns:xsi="www.w3/2001/XMLSchema-instance" xmlns:p="www.springframework/schema/p" xsi:schemaLocation="www.springframework/schema/beans www.springframework/schema/beans/spring-beans-3.0.xsd"> <bean id="dataSource" class="org.apachemons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://my server/emp_app"></property> <property name="username" value="root"></property> <property name="password" value="root"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> </props> </property> </bean> <bean id="d" class="login.HrDao"> <property name="sessionFactory" ref="mysessionFactory"></property> </bean> </beans>

我的HrDAO.java文件 - >

my HrDAO.java file ->

package login; import org.hibernate.SessionFactory; import org.springframework.orm.hibernate3.HibernateTemplate; public class HrDao { HibernateTemplate template; public void setSessionFactory(SessionFactory factory) { template = new HibernateTemplate(factory); } public void saveStudent(HrModel e) { template.save(e); } }

我的HrMain。 java文件 - >

MY HrMain.java File ->

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>

推荐答案

您的 applicationContext在哪里? XML ?您可以将 web.xml 中的 applicationContext.xml 引用为:

Where is your applicationContext.xml? You can refer your applicationContext.xml in web.xml as:

<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param>

更多推荐

导致:java.io.FileNotFoundException:无法打开ServletContext资源[/applicationContext.xml]

本文发布于:2023-10-28 17:48:14,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法打开   资源   FileNotFoundException   io   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!