servlet上下文中的NoSuchMethodError

时间:2014-07-04 10:02:48

标签: java maven servlets

我有两个maven模块:commonwebapp

他们拥有相同的父项目,webapp取决于common

MapServer模块中有一个班级common

public class MapServer {
    public TileResponse getTileResponse(Coord coordinate, int size, String format, String[] layers) {
        ....
        return null;
    }
}

我可以这样运行:

public static void main(....){
    ....
    TileResponse tileResponse = mapServer.getTileResponse(coord, 256, "png", new String[]{"layer"});
}

它有效(获得了所需的结果,没有任何错误)。

但是,一旦我通过servlet运行webapp模块,

public class ServeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
            ......
            tileResponse = mapServer.getTileResponse(coord, 256,format , layers.split(","));
    }

}

我收到了错误:

July 04, 2014 5:55:36 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [tile] in context with path [/test] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoSuchMethodError: MapServer.getTileResponse(Lcore/Coord;ILjava/lang/String;[Ljava/lang/String;)LTileResponse;

发生了什么?

我正在使用tomcat maven plugin

<build>
    <finalName>webapp</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <port>8080</port>
                <path>/test</path>
                <uriEncoding>UTF-8</uriEncoding>
                <finalName>gtwebapp</finalName>
                <server>tomcat7</server>
            </configuration>
        </plugin>
    </plugins>
</build>

1 个答案:

答案 0 :(得分:2)

java.lang.NoSuchMethodError指示用于构建调用代码的类(在您的情况下为MapServer)的版本与运行时可用的版本不同。

一旦您对MapServer的工作版本感到满意:

  • 重建公共项目并将其安装到您当地的maven repo
  • 针对此版本的公共项目重建webapp
  • 再次尝试重新部署tomcat之前的tomcat
相关问题