java - Servlet 上下文中的 NoSuchMethodError

标签 java maven servlets

我有两个 Maven 模块:commonwebapp

他们有相同的父项目,并且 webapp取决于common .

有一个类MapServercommon模块:

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"});
}

它成功了(得到了期望的结果,没有任何错误)。

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

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>

最佳答案

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

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

  • 重建通用项目并将其安装到本地 Maven 存储库中
  • 针对此版本的公共(public)项目重新构建 Web 应用
  • 在重试之前在 tomcat 上重新部署 Web 应用

关于java - Servlet 上下文中的 NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24571722/

相关文章:

java - 使用 Servlet 重定向 REST 请求

java - J2EE 和 Angular HTTP POST servlet

java - Android Studio 按钮导致崩溃

java - 第二个数组不打印

maven - 吊带模型 OSGI 配置

java - 获取maven插件在自己的Mojo中的目录路径

java - 如何将一组类从 jar 库映射到 jpa 实体以创建数据库表

java - 如何连接到 java 中的 Binder C++ 服务?

java - Spring:Bean B 加载完成后如何初始化 Bean A?

java - 使用 CloudSQL 代理连接到 Google CloudSQL