我的Spring应用程序无法加载Servlet上下文

时间:2015-05-19 13:27:53

标签: java spring spring-mvc

我正在开发Spring4.1.6版本。我在Tomcat 7.0上部署了名为SpringMVCTest的Web应用程序。我在tomcat启动时遇到以下异常。以下是弹簧配置文件的详细信息。

的web.xml

<web-app 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_3_0.xsd"
    version="3.0">
    <display-name>SpringMVC Test Web Application</display-name>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/config/spring/webmvc-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

我已经在web.xml中添加了contextConfigLocation参数,下面是webmvc-config.xml的内容

<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byName"
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="
         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd 
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd 
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Scans within the base package of the application for @Components to configure as beans -->
    <!-- @Controller, @Service, @Configuration, etc. -->
    <context:component-scan base-package="com.springmvc" />
    <!-- Enables the Spring MVC @Controller programming model -->
    <mvc:annotation-driven />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

</beans>

Bean类

/**
 * 
 */
package com.springmvc.bean.Person;

import java.util.List;

/**
 * @author jp48346
 *
 */
public class Person {

    private String name;
    private String email;
    private String gender;
    private String password;
    private String passwordConf;
    private List<String> courses;
    private String tutor;
    private String hiddenMessage;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getGender() {
        return gender;
    }
    public void setGender(String gender) {
        this.gender = gender;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getPasswordConf() {
        return passwordConf;
    }
    public void setPasswordConf(String passwordConf) {
        this.passwordConf = passwordConf;
    }
    public List<String> getCourses() {
        return courses;
    }
    public void setCourses(List<String> courses) {
        this.courses = courses;
    }
    public String getTutor() {
        return tutor;
    }
    public void setTutor(String tutor) {
        this.tutor = tutor;
    }
    public String getHiddenMessage() {
        return hiddenMessage;
    }
    public void setHiddenMessage(String hiddenMessage) {
        this.hiddenMessage = hiddenMessage;
    }

}

PersonRegistration.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>test Spring MVC Sample</title>
</head>
<body>
<h2>Fill your form!</h2>
 <form:form method="POST" commandName="form">
     <table>
            <tr>
                <td>Enter your name:</td>
                <td><form:input path="name" /></td>
                <td><form:errors path="name" cssStyle="color: #ff0000;"/></td>
            </tr>
            <tr>
                <td><input type="submit" name="submit" value="Submit"></td>
            </tr>
    </table>
</form:form>        

</body>
</html>

但我不明白为什么我仍然得到以下例外?根据日志,为什么它还在尝试在WEB-INF目录中查找applicationContext.xml?请帮助我解决这个问题,如果需要任何其他信息来解决问题,请告诉我。

  

信息:从ServletContext资源加载XML bean定义   [/WEB-INF/applicationContext.xml] 2015年5月19日下午6:36:01   org.springframework.web.context.ContextLoader   initWebApplicationContext SEVERE:上下文初始化失败   org.springframework.beans.factory.BeanDefinitionStoreException:   IOException从ServletContext资源解析XML文档   [/WEB-INF/applicationContext.xml的];嵌套异常是   java.io.FileNotFoundException:无法打开ServletContext资源   [/WEB-INF/applicationContext.xml] at   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)     在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)     在   org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)     在   org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)     在   org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)     在   org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)     在   org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)     在   org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)     在   org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)     在   org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)     在   org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)     在   org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)     在   org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)     在   org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)     在   org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528)     在   org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在   org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1575)     在   org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1565)     在java.util.concurrent.FutureTask.run(FutureTask.java:262)at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)     在java.lang.Thread.run(Thread.java:745)引起:   java.io.FileNotFoundException:无法打开ServletContext资源   [/WEB-INF/applicationContext.xml] at   org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)     在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)     ......还有21个

0 个答案:

没有答案