无法运行弹簧应用程序?

时间:2013-12-24 07:50:48

标签: spring spring-mvc

我是Spring的新手我正在尝试运行spring应用程序,我得到的DispatcherServlet类未找到异常。以下是我用过的代码,有人可以帮帮我吗?我尝试了stackoverflow和谷歌提供的许多解决方案,但我没有得到这个问题的答案。提前谢谢。

package com.raistudies.actions;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloWorldAction {

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public ModelAndView sayHello(Model model) {
        System.out.println(" hellow world ");
        ModelAndView mav = new ModelAndView();
        mav.setViewName("hello");
        model.addAttribute("helloMessage",
                "Hello World from my spring 3 mvc application");
        return mav;
    }
}

hello.jsp - WEB-INF / jsp /

<html>
    <head>
        <title>Hello world with spring 3 mvc </title>
    </head>
    <body>
        <h1>Welcome! Spring MVC is working well.</h1><br />
        ${helloMessage}
    </body>
</html>

index.jsp - WEB-INF

 <html>
    <head>
        <title>rai studies</title>
    </head>
    <body>

            Welcome...
            <a href="hello"><br>Click here to check the output :-)</a>
    </body>
    </html>

应用-config.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <context:component-scan base-package="com.raistudies.actions" />
    <context:annotation-config />

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

</beans>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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_3_0.xsd"
    id="WebApp_ID" version="3.0">

    <display-name>HWEWS3MVCIE</display-name>

    <servlet>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <servlet-class>org.springfrmaework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/app-config.xml</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

我的依赖项:

commons-logging-1.1.2.jar
jstl-1.2.jar
log4j-1.2.16.jar
spring-aspects-3.2.5.RELEASE.jar
spring-beans-3.2.5.RELEASE.jar
spring-context-3.2.5.RELEASE.jar
spring-core-3.2.5.RELEASE.jar
spring-expression-3.2.5.RELEASE.jar
spring-web-3.2.5.RELEASE.jar
spring-webmvc-3.2.5.RELEASE.jar

1 个答案:

答案 0 :(得分:1)

<servlet-class>org.springfrmaework.web.servlet.DispatcherServlet</servlet-class>

在上面的行中有拼写错误。它应该是

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>