在Tomcat上部署Spark Java

时间:2015-05-14 21:53:07

标签: java tomcat

我想在tomcat上部署SparkJava。在web.xml中我有

<filter>
        <filter-name>SparkFilter</filter-name>
        <filter-class>spark.servlet.SparkFilter</filter-class>
        <init-param>
            <param-name>RestCheckerService</param-name>
            <param-value>rest.RestCheckerService</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>SparkFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

当我尝试部署Spark时,我遇到了这个错误:

javax.servlet.ServletException: java.lang.NullPointerException
    at spark.servlet.SparkFilter.getApplication(SparkFilter.java:92)
    at spark.servlet.SparkFilter.init(SparkFilter.java:70)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) 
...
Caused by: java.lang.NullPointerException
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at spark.servlet.SparkFilter.getApplication(SparkFilter.java:89)

我的过滤器类

public class RestCheckerService implements SparkApplication{
  ...

    @Override
    public void init() {
      ...

        Spark.get("/scheme/:groupName/:schemeName/:version", new Route() {
            @Override
            public Object handle(Request request, Response response) {
                try {
return gson.toJson(clientDB.getScheme(request.params(":groupName"), request.params(":schemeName"), Integer.parseInt(request.params(":version"))));

                } catch (DaoException e) {
                    return RestErrorCodes.ERROR;
                }
            }
        });

    }

也许是因为我使用的是Java7而不是Java8

1 个答案:

答案 0 :(得分:4)

替换

<param-name>RestCheckerService</param-name>

<param-name>applicationClass</param-name>