信息: Marking servlet dispatcher as unavailable


 

在寫spring MVC的demo時,啟動tomcat后,訪問鏈接報404錯誤,提示相應的servlet不生效,

控制台有以下錯誤信息:

2013-10-23 10:07:39 org.apache.catalina.core.StandardContext loadOnStartup
嚴重: Servlet /webtest threw load() exception
java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
 at org.springframework.web.servlet.DispatcherServlet.<clinit>(DispatcherServlet.java:223)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

 

缺少一個日志組件,以前寫一直也沒問題,所以認為這個錯誤只是tomcat啟動后不會記日志,不影響程序,

所以沒往這個方向查,一直沒解決,最后發現原來真是這個問題,

將commons-logging-1.0.4.jar添加到WEB-INF/lib下,再重啟就沒問題了

 

附上springMVC的demo以做備注

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>webtest</display-name>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <description>加載/WEB-INF/spring-mvc/目錄下的所有XML作為Spring MVC的配置文件</description>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-mvc/*.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

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

dispatcher-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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/aop 
            http://www.springframework.org/schema/aop/spring-aop-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/mvc 
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <!--
        使Spring支持自動檢測組件,如注解的Controller
    -->
    <context:component-scan base-package="com.controller"/>
   
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/"
          p:suffix=".jsp" />
</beans>
View Code

 

控制器代碼

package com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class IndexController {
        @RequestMapping("/index")
        public String index(String username) {
            System.out.print(username);
            return "index";
        }

}
View Code

通過http://localhost:8088/webtest/index/xu.htm 即可訪問

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM