在这里,您可以找到有关部署的信息:http://sparkjava.com/documentation.html#embedded-web-server
首先,为配置设置过滤器选项:web.xml
<web-app>
<!-- some options -->
<filter>
<filter-name>SparkFilter</filter-name>
<filter-class>spark.servlet.SparkFilter</filter-class>
<init-param>
<param-name>applicationClass</param-name>
<param-value>your.package.Application</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SparkFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Application
类应该实现接口,并且必须在方法中初始化路由。spark.servlet.SparkApplication
init()
这个看起来像(在Java SE 8中,您可以将Lambda表达式用于路由器。
package your.package;
import static spark.Spark.*;
public class Application implements SparkApplication {
@Override
public void init() {
get("/", (request, response) -> "Hello World");
get("/hello/:name", (request, response) -> {
return "Hello: " + request.params(":name");
});
}
}
具有此配置的应用程序适用于雄猫和玻璃鱼服务器。