복붙노트

[SPRING] HTTP 상태 500 - 서블릿 Dispatcher에 대한 Servlet.init ()가 예외를 발생했습니다.

SPRING

HTTP 상태 500 - 서블릿 Dispatcher에 대한 Servlet.init ()가 예외를 발생했습니다.

이 간단한 HTML 폼을 실행하려고 할 때 :

   <html>
       <head>
        <title>Enter a new Page</title>
       </head>

       <body>

          <div id="editPresPage">
             <form action="editPresPage.do" method="post"> 
            <label>Enter Page ID</label><input type="text" name="page_id"/>
            <label>Enter Header1</label><input type="text" name="h1"/>
            <label>Enter Header2</label><input type="text" name="h2"/>
            <label>Enter Header3</label><input type="text" name="h3"/>
            <label>Enter Header4</label><input type="text" name="h4"/>            
            <label>Enter Page Text</label><input type="text" name="page_text"/>

            <input type="submit" value="Add New Page"/>
         </form>              
          </div>


       </body>
    </html>

서블릿 Dispatcher에 대한 Servlet.init () 오류 HTTP 상태 500이 표시됩니다. 브라우저에서 예외가 발생했습니다.

내 명령 행 창 (바람둥이의 start.batch 파일을 실행할 때 열림) 다음과 같은 오류가 발생합니다.

My Dispatcher-servlet.xml 파일 :

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context"
    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">       

        <import resource="/application.xml"/>

        <bean name="/editPresPage.do"
                class="my.pack.webTier.control.EditPresPageController" >
            <property name="page_manager_service" ref="page_manager_service"/>
        </bean> 

       <!--  I also tried using with annotations -->    
        <!-- <context:component-scan base-package="my.pack"/> -->        

</beans>

나는 필레를 가지고있다 :

<?xml version="1.0" encoding="UTF-8"?>
<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_2_5.xsd"
         version="2.5">

    <servlet>
       <servlet-name>Dispatcher</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
       <servlet-name>Dispatcher</servlet-name>
       <url-pattern>*.do</url-pattern>
</servlet-mapping>

    <!-- Tomcat configuration -->
    <Context path="/myWebApp" docBase="../tomcat\work\Catalina\localhost\mywebapptomcat\work\Catalina\localhost\mywebapp">
    <Loader
    loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
    </Context>

</web-app>

그리고 그건 내 컨트롤러 다.

package my.pack.webTier.control;

import my.pack.dataAccessTier.domain.Presentation_page;
import my.pack.serviceTier.services.Page_manager_service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

//@Controller
public class EditPresPageController {

    //@Autowired
    private Page_manager_service page_manager_service;

    public void setPage_manager_service(Page_manager_service page_manager_service) {
        this.page_manager_service = page_manager_service;
    }

    @RequestMapping("/editPresPage")
    public ModelAndView EditPresPage(@RequestParam("page_id") int page_id,
                                     @RequestParam("h1") String h1_value,
                                     @RequestParam("h2") String h2_value,
                                     @RequestParam("h3") String h3_value,
                                     @RequestParam("h4") String h4_value,
                                     @RequestParam("page_text") String page_text)

    {
        Presentation_page new_page=new Presentation_page(page_id,h1_value,h2_value,
                h3_value,h4_value,page_text);

        page_manager_service.create_new_page(new_page);


        return new ModelAndView("/thanks.html");

    }


}

stacktrace 예외 :

javax.servlet.ServletException: Servlet.init() for servlet Dispatcher threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    java.lang.Thread.run(Thread.java:722)

스프링 MVC 3.2, 일식 3.7, springTomcat / 7.0.30 및 ANT 프로젝트를 사용하고 있습니다.

나는이 요구 사항에 대한 해답을 찾았고 하나도 찾지 못했습니다.

해결법

  1. ==============================

    1.디스패처를 * .do에 매핑합니다.

    디스패처를 * .do에 매핑합니다.

    <servlet-mapping>
       <servlet-name>Dispatcher</servlet-name>
       <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    

    컨트롤러는 .do없이 url에 매핑됩니다.

    @RequestMapping("/editPresPage")
    

    이것을 다음으로 변경해보십시오 :

    @RequestMapping("/editPresPage.do")
    
  2. ==============================

    2.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>teste4</groupId>
        <artifactId>teste4</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>war</packaging>
    
        <repositories>
            <repository>
                <id>prime-repo</id>
                <name>PrimeFaces Maven Repository</name>
                <url>http://repository.primefaces.org</url>
                <layout>default</layout>
            </repository>
        </repositories>
    
    
    
        <dependencies>
            <dependency>
                <groupId>com.sun.faces</groupId>
                <artifactId>jsf-impl</artifactId>
                <version>2.2.4</version>
            </dependency>
    
    
            <dependency>
                <groupId>com.sun.faces</groupId>
                <artifactId>jsf-api</artifactId>
                <version>2.2.4</version>
            </dependency>
    
    
    
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                <version>1.2</version>
            </dependency>
            <dependency>
                <groupId>org.primefaces</groupId>
                <artifactId>primefaces</artifactId>
                <version>4.0</version>
            </dependency>
            <dependency>
                <groupId>org.primefaces.themes</groupId>
                <artifactId>bootstrap</artifactId>
                <version>1.0.9</version>
            </dependency>
            <dependency>
                <groupId>commons-fileupload</groupId>
                <artifactId>commons-fileupload</artifactId>
                <version>1.3</version>
            </dependency>
    
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.27</version>
            </dependency>
    
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>4.2.7.Final</version>
            </dependency>
    
        </dependencies>
    
    
    </project>
    
  3. from https://stackoverflow.com/questions/14968318/http-status-500-servlet-init-for-servlet-dispatcher-threw-exception by cc-by-sa and MIT license