首页 > 解决方案 > 在 Eclipse 中运行 Spring 应用程序时出现错误:-

问题描述

在 Eclipse Maven 项目中运行 Spring MVC 项目时出现错误,附加了工作区图像。我有一个非常简单的弹簧测试应用程序。但我得到了例外,即使一切似乎都正常。我可能遗漏了一些东西。请帮忙。请帮助解决这个问题。请帮助解决这个问题。请帮助解决这个问题。请帮助解决这个问题。

错误 :-

    SEVERE: Context initialization failed
    org.springframework.beans.factory.BeanDefinitionStoreException: 
    IOException parsing XML document from ServletContext resource [/WEB- 
    INF/employee-servlet.xml]; nested exception is 
    java.io.FileNotFoundException: Could not open ServletContext resource 
    [/WEB-INF/employee-servlet.xml]
    at 

    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.
    loadBeanDefinitions(XmlBeanDefinitionReader.java:343)

    Caused by: java.io.FileNotFoundException: Could not open ServletContext 
    resource [/WEB-INF/employee-servlet.xml]
      at 
    org.springframework.web.context.support.ServletContextResource.
    getInputStream(ServletContextResource.java:159)
      at 

    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.
    loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
     ... 21 more

    Jun 24, 2018 8:00:45 PM org.apache.catalina.core.StandardContext 
    listenerStart
    SEVERE: Exception sending context initialized event to listener instance 
    of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanDefinitionStoreException: 
    IOException parsing XML document from ServletContext resource [/WEB- 
    INF/employee-servlet.xml]; nested exception is 
     java.io.FileNotFoundException: Could not open ServletContext resource 
   [/WEB-INF/employee-servlet.xml]


     My Project Structure :- 

    [enter image description here][1]

web.xml

    <?xml version="1.0" encoding="UTF-8"?>

  <web-app
   xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">

  <display-name>Archetype Created Web Application</display-name>
    <welcome-file-list>
    <welcome-file>/WEB-INF/index.jsp</welcome-file>
    </welcome-file-list>
  <servlet>
    <servlet-name>employee</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
    <servlet-name>employee</servlet-name>
    <url-pattern>/</url-pattern>
 </servlet-mapping>
 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/employee-servlet.xml</param-value>
 </context-param>
 <listener>
    <listener- class>org.springframework.web.context.ContextLoaderListener
 </listener-class>
 </listener>

员工-servlet.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:aop="http://www.springframework.org/schema/aop"
     xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xmlns:lang="http://www.springframework.org/schema/lang"
      xmlns:p="http://www.springframework.org/schema/p"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:util="http://www.springframework.org/schema/util"
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop.xsd
      http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/jee 
       http://www.springframework.org/schema/jee/spring-jee.xsd
       http://www.springframework.org/schema/lang 
       http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util.xsd">
      <context:annotation-config />
      <context:component-scan base-package="com.SpringHibernate.Controller" 
       />
      <bean id="jspViewResolver" class = 
      "org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="viewClass" 
      value="org.springframework.web.servlet.view.JstlView"></property>
      <property name="prefix" value="/WEB-INF"></property>
      <property name="suffix" value=".jsp"></property>
      </bean>
           <bean id="messageSource" 
           class="org.springframework.context.support.
            ReloadableResourceBundleMessageSource">
            <property name="basename" value="classpath:messages"></property>
            <property name="defaultEncoding" value="UTF-8"></property>
           </bean>
            <bean id="propertyConfigurer" 
               class="org.springframework.beans.factory.config.
                 PropertyPlaceholderConfigurer"
                    p:location = "/WEB-INF/jdbc.properties">
                  </bean>

    <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
    p:driverClassName="${jdbc.driverClassName}"
    p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
    p:password="${jdbc.password}">
   </bean>

    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="configLocation">
        <value>classpath:hibernate.cfg.xml</value>
    </property>

   <!--   

    <property name="configurationClass">
        <value>org.hibernate.cfg.AnnotationConfiguration</value>
    </property>



    <property name="hibernateProperties">
        <props>
            <prop 

             key="hibernate.dialect">org.hibernate.dialect.
              MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
-->

      </bean>
       <bean id="employeeDAO" 
         class="com.SpringHibernate.Dao.EmployeeDAOImpl"></bean>
          <bean id="employeeManager" 
          class="com.SpringHibernate.service.EmployeeManagerImpl"></bean>
           <tx:annotation-driven /> 
          <bean id="transactionManager"
            class="org.springframework.orm.hibernate5.
       HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
        </bean>
        </beans>

         Please guide on this issue.I am novice in Spring MVC.

标签: spring-mvc

解决方案


推荐阅读