我想在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
最佳答案
更换
<param-name>RestCheckerService</param-name>
与
<param-name>applicationClass</param-name>