Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

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

I have a problem with egovframework of Korea when I have deployed file war to Tomcat after I restarted Tomcat, it showed the error like below :

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)
....................................................

I used :

[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)

Here is file 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>

Here is /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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

That method was added in Servlet 2.5.

So this problem can have at least 3 causes:

  1. The servlet container does not support Servlet 2.5.
  2. The web.xml is not declared conform Servlet 2.5 or newer.
  3. The webapp's runtime classpath is littered with servlet container specific JAR files of a different servlet container make/version which does not support Servlet 2.5.

To solve it,

  1. Make sure that your servlet container supports at least Servlet 2.5. That are at least Tomcat 6, Glassfish 2, JBoss AS 4.1, etcetera. Tomcat 5.5 for example supports at highest Servlet 2.4. If you can't upgrade Tomcat, then you'd need to downgrade Spring to a Servlet 2.4 compatible version.
  2. Make sure that the root declaration of web.xml complies Servlet 2.5 (or newer, at least the highest whatever your target runtime supports). For an example, see also somewhere halfway our servlets wiki page.
  3. Make sure that you don't have any servlet container specific libraries like servlet-api.jar or j2ee.jar in /WEB-INF/lib or even worse, the JRE/lib or JRE/lib/ext. They do not belong there. This is a pretty common beginner's mistake in an attempt to circumvent compilation errors in an IDE, see also How do I import the javax.servlet API in my Eclipse project?.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...