在Eclipse中运行Spring Application时出现错误:

时间:2018-06-24 15:11:45

标签: spring-mvc

在Eclipse Maven Project中运行Spring MVC Project时,出现以下错误, 附件中的工作区 我有一个非常简单的春季测试应用程序。但是,即使一切似乎都井井有条,我还是感到异常。我可能会丢失一些东西。请对此提供帮助。 请帮忙。 请帮忙。 请帮忙。 请对此提供帮助。

错误:-

    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>

employee-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.

0 个答案:

没有答案