web-dev-qa-db-ja.com

java.lang.NoSuchMethodError:javax.servlet.ServletContext.getContextPath()Ljava / lang / String;

Tomcatを再起動した後、Tomにファイルウォーを展開すると、韓国のegovframeworkに問題があります。次のようなエラーが表示されました。

2011-12-23 09:16:01,101 ERROR [org.springframework.web.servlet.DispatcherServlet] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'imageRenderer' defined in ServletContext resource [/WEB-INF/config/egovframework/springmvc/egov-com-servlet.xml]: Initialization of bean failed; nested exception is Java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:527)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:291)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:288)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:190)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.Java:580)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:895)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:425)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.Java:442)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.Java:458)
        at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.Java:339)
        at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.Java:306)
        at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.Java:127)
        at javax.servlet.GenericServlet.init(GenericServlet.Java:212)
        at org.Apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.Java:1139)
        at org.Apache.catalina.core.StandardWrapper.allocate(StandardWrapper.Java:791)
        at org.Apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.Java:660)
        at org.Apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.Java:469)
        at org.Apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.Java:403)
....................................................

私は使用しました:

[root@localhost bin]# Java -version

Java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.10) (rhel-1.23.1.9.10.el5_7-i386)
OpenJDK Client VM (build 19.0-b09, mixed mode)

これはWEB-INF/web.xmlファイルです

<display-name>spring security</display-name>
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>*.mdo</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>HTMLTagFilter</filter-name>
        <filter-class>egovframework.com.cmm.filter.HTMLTagFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>HTMLTagFilter</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>

        <!-- 0. 로그인 정책 컴포넌트용 필터 -->
        <!--
    <filter>
        <filter-name>LoginPolicyFilter</filter-name>
        <filter-class>egovframework.com.uat.uap.filter.EgovLoginPolicyFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>LoginPolicyFilter</filter-name>
        <url-pattern>/uat/uia/actionLogin.do</url-pattern>
    </filter-mapping>
     -->
        <!-- Restoration from HTMLTagFilter's action (certification login) -->

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:egovframework/spring/com/context-*.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/config/egovframework/springmvc/egov-com-*.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

        <!-- 1. Spring Security 필터 설정-->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.springframework.security.ui.session.HttpSessionEventPublisher</listener-class>
    </listener>

        <!-- 2. Spring Security 로그아웃 설정을 위한 필터 설정 -->
        <filter>
        <filter-name>EgovSpringSecurityLogoutFilter</filter-name>
        <filter-class>egovframework.com.sec.security.filter.EgovSpringSecurityLogoutFilter</filter-class>
        </filter>
        <filter-mapping>
        <filter-name>EgovSpringSecurityLogoutFilter</filter-name>
        <url-pattern>/uat/uia/actionLogout.do</url-pattern>
        </filter-mapping>

        <!-- 2. Spring Security 로그인 설정을 위한 필터 설정 -->
        <filter>
        <filter-name>EgovSpringSecurityLoginFilter</filter-name>
        <filter-class>egovframework.com.sec.security.filter.EgovSpringSecurityLoginFilter</filter-class>
                <init-param>
                        <description>로그인 실패시 반활 될 URL설정</description>
                        <param-name>loginURL</param-name>
                        <param-value>/uat/uia/egovLoginUsr.do</param-value>
                </init-param>
        </filter>
        <filter-mapping>
        <filter-name>EgovSpringSecurityLoginFilter</filter-name>
        <url-pattern>*.do</url-pattern>
        </filter-mapping>

        <!-- 3. EgovSSO 로그아웃 설정을 위한 필터 설정 -->
    <!--
    <filter>
        <filter-name>EgovSSOLogoutFilter</filter-name>
        <filter-class>egovframework.com.uat.sso.filter.EgovSSOLogoutFilter</filter-class>
                <init-param>
                        <description>SSO Global Logout 처리후 반환되는 페이지 설정</description>
                        <param-name>returnURL</param-name>
                        <param-value>/j_spring_security_logout</param-value>
                </init-param>
        </filter>
        <filter-mapping>
        <filter-name>EgovSSOLogoutFilter</filter-name>
        <url-pattern>/uat/uia/actionLogout.do</url-pattern>
        </filter-mapping>
        -->

        <!-- 3. EgovSSO 로그인 설정을 위한 필터 설정 -->
    <!--
    <filter>
        <filter-name>EgovSSOLoginFilter</filter-name>
        <filter-class>egovframework.com.uat.sso.filter.EgovSSOLoginFilter</filter-class>
        </filter>
        <filter-mapping>
        <filter-name>EgovSSOLoginFilter</filter-name>
        <url-pattern>*.do</url-pattern>
        </filter-mapping>
        -->


    <!-- AjaxTags configuration START-->
    <servlet>
        <servlet-name>ajaxServlet</servlet-name>
        <servlet-class>net.sourceforge.ajaxtags.servlets.SourceLoader</servlet-class>
        <init-param>
            <param-name>prefix</param-name>
            <param-value>/ajaxtags</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>ajaxServlet</servlet-name>
        <url-pattern>/ajaxtags/js/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ajaxServlet</servlet-name>
        <url-pattern>/ajaxtags/img/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ajaxServlet</servlet-name>
        <url-pattern>/ajaxtags/css/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>egovDevIndex.jsp</welcome-file>
    </welcome-file-list>
    <login-config>
        <auth-method>BASIC</auth-method>
    </login-config>

    <session-config>
        <session-timeout>600</session-timeout>
    </session-config>

    <error-page>
      <error-code>404</error-code>
      <location>/code404.jsp</location>
    </error-page>
    <error-page>
      <error-code>500</error-code>
      <location>/code500.jsp</location>
    </error-page>

</web-app>

これは/WEB-INF/config/egovframework/springmvc/egov-com-servlet.xmlです

<?xml version="1.0" encoding="UTF-8"?>
<!--
        수정일                 수정자                          수정내용
  =========     =======    =================================================
  2011.09.07    서준식                  로그인 체크 인터셉터 추가
  2011.09.29    이기하                  에러페이지 경로수정
-->
<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"
                xmlns:aop="http://www.springframework.org/schema/aop"
                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">

        <!-- The controllers are autodetected POJOs labeled with the @Controller annotation. -->
        <context:component-scan base-package="egovframework, example">
                <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
                <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
                <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
        </context:component-scan>


        <!-- For Pagination Tag -->
        <bean id="imageRenderer" class="egovframework.com.cmm.ImagePaginationRenderer"/>

        <bean id="paginationManager" class="egovframework.rte.ptl.mvc.tags.ui.pagination.DefaultPaginationManager">
                <property name="rendererType">
                        <map>
                                <entry key="image" value-ref="imageRenderer"/>
                        </map>
                </property>
        </bean>

        <!--
                - The form-based controllers within this application provide @RequestMapping
                - annotations at the type level for path mapping URLs and @RequestMapping
                - at the method level for request type mappings (e.g., GET and POST).
                - In contrast, ClinicController - which is not form-based - provides
                - @RequestMapping only at the method level for path mapping URLs.
                -
                - DefaultAnnotationHandlerMapping is driven by these annotations and is
                - enabled by default with Java 5+.
        -->

        <!--
                - This bean processes annotated handler methods, applying Application-specific PropertyEditors
                - for request parameter binding. It overrides the default AnnotationMethodHandlerAdapter.
        -->
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
                <property name="webBindingInitializer">
                        <bean class="egovframework.com.cmm.web.EgovBindingInitializer"/>
                </property>
                <property name="customArgumentResolvers">
                        <list>
                                <bean class="egovframework.rte.ptl.mvc.bind.CommandMapArgumentResolver"/>
                        </list>
                </property>
        </bean>

        <!-- 로그인 체크가 필요한 URL과 로그인 여부를 체크해줄 인터셉터를 등록한다. -->
        <!--
        <bean id="selectAnnotaionMapper" class="egovframework.rte.ptl.mvc.handler.SimpleUrlAnnotationHandlerMapping" p:order="1">
                <property name="interceptors">
                        <list>
                                <ref local="authenticInterceptor" />
                        </list>
                </property>
                -->
                <!-- 로그인 체크가 필요한 URL 리스트  -->
                <!--
                <property name="urls">
                        <set>
                                <value>/**/*.do</value>
                        </set>
                </property>
        </bean>
        -->

        <!-- 로그인 체크 인터셉터 -->
        <!-- <bean id="authenticInterceptor" class="egovframework.com.cmm.interceptor.AuthenticInterceptor"> -->
        <!-- 인증 체크가 필요 없는 URL 리스트  -->
        <!--
                <property name="permittedURL">
                        <set>
                                <value>/uat/uia/[a-zA-Z]+\.do</value>
                                <value>/EgovLeft.do</value>
                                <value>/uat/uia/actionLogin.do</value>
                        </set>
                </property>
        </bean>
        -->

        <!--
                - This bean resolves specific types of exceptions to corresponding logical
                - view names for error views. The default behaviour of DispatcherServlet
                - is to propagate all exceptions to the servlet container: this will happen
                - here with all other types of exceptions.
        -->
        <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
                <property name="defaultErrorView" value="egovframework/com/cmm/error/egovError"/>
                <property name="exceptionMappings">
                        <props>
                                <prop key="org.springframework.dao.DataAccessException">egovframework/com/cmm/error/dataAccessFailure</prop>
                                <prop key="org.springframework.transaction.TransactionException">egovframework/com/cmm/error/dataAccessFailure</prop>
                                <prop key="egovframework.rte.fdl.cmmn.exception.EgovBizException">egovframework/com/cmm/error/egovBizException</prop>
                                <prop key="org.springframework.web.HttpSessionRequiredException">egovframework/com/uat/uia/EgovLoginUsr</prop>
                        </props>
                </property>
        </bean>

        <!--
                - This bean configures the 'prefix' and 'suffix' properties of
                - InternalResourceViewResolver, which resolves logical view names
                - returned by Controllers. For example, a logical view name of "vets"
                - will be mapped to "/WEB-INF/jsp/vets.jsp".
        -->
        <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="1"
                  p:viewClass="org.springframework.web.servlet.view.JstlView"
                  p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>

        <!--
                - Message source for this context, loaded from localized "messages_xx" files.
                - Could also reside in the root application context, as it is generic,
                - but is currently just used within Application's web tier.
        -->
        <!-- <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages/message-common"/> -->
</beans>
33
sonida

Java.lang.NoSuchMethodError:javax.servlet.ServletContext.getContextPath()Ljava/lang/String;

このメソッドは Servlet 2.5 で追加されました。

したがって、この問題には少なくとも3つの原因があります。

  1. サーブレットコンテナはサーブレット2.5をサポートしていません。
  2. web.xmlは、Servlet 2.5以降に準拠していると宣言されていません。
  3. Webappのランタイムクラスパスには、サーブレット2.5をサポートしていない異なるサーブレットコンテナのメーカー/バージョンのサーブレットコンテナ固有のJARファイルが散らばっています。

それを解決するために、

  1. サーブレットコンテナが少なくともサーブレット2.5をサポートしていることを確認してください。少なくともTomcat 6、Glassfish 2、JBoss AS 4.1などです。たとえば、Tomcat 5.5はServlet 2.4でサポートしています。 Tomcatをアップグレードできない場合は、SpringをServlet 2.4互換バージョンにダウングレードする必要があります。
  2. web.xmlのルート宣言がServlet 2.5(または、少なくとも、ターゲットランタイムがサポートする最高のもの)に準拠していることを確認してください。例については、途中で参照してください サーブレットwikiページ
  3. servlet-api.jarまたはj2ee.jarまたは/WEB-INF/libJRE/libJRE/lib/extなどのサーブレットコンテナ固有のライブラリがないことを確認してください。彼らはそこに属していません。これは、IDEでコンパイルエラーを回避しようとするかなり一般的な初心者の間違いです。 Eclipseプロジェクトでjavax.servlet APIをインポートするにはどうすればよいですか も参照してください。
72
BalusC