Spark休息api服务器部署 [英] Spark rest api server deploy

查看:123
本文介绍了Spark休息api服务器部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用这个链接,我让rest api server 。当我在eclipse ide上运行时,它运行良好。但是,我不知道如何在服务器上部署。我制作了war文件,并尝试在tomcat上进行部署,但不知何故无法访问我定义的任何页面,这与在eclipse上运行的不同。这是我做的一些gradle配置。

  apply plugin:'war'

war {
baseName ='server'
manifest {
attributes'Implementation-Title':'SparkAPIServer','Implementation-Version':'1.0','Main-Class':'com.server.Main'
}
}

我确定'Main-Class'路径是正确的。对此的任何想法?解决方案

从Eclipse IDE运行与在Tomcat上运行不同,因为在Eclipse上运行时使用Spark内置的Jetty服务器,以及部署到Tomcat Spark时在Tomcat服务器上运行。



documentation


其他网络服务器

要在web服务器(而不是嵌入式jetty服务器)上运行Spark,
接口spark.servlet.SparkApplication的实现是
需要。你必须在init()方法中初始化路由,并且必须在你的web.xml中配置
以下过滤器:

...


因此,为了在部署到Tomcat后运行相同的代码,您需要:


  1. 您的类应该实现SparkApplication。
  2. 实现init()方法,并在那里注册所有路由。 (当然,如果您希望能够在Eclipse上本地运行并在Tomcat上远程运行,只需将所有路由注册到一些私有方法startSpark(),这将从init()和main()中调用)。

  3. 您的web.xml应该相应地设置。


With this link, I made rest api server. It works well when I run on eclipse ide. However, I don't know how to deploy on server. I made war file and tried to deploy on tomcat, but somehow cannot access any page that I defined, unlike running on eclipse. Here is some gradle configuration that I made.

apply plugin: 'war'

war {
    baseName = 'server'
    manifest {
        attributes 'Implementation-Title': 'SparkAPIServer', 'Implementation-Version': '1.0', 'Main-Class': 'com.server.Main'
    }
}

I'm sure that 'Main-Class' path is correct. Any idea of this?

解决方案

Running from Eclipse IDE is not the same like running on Tomcat, because when running on Eclipse Spark uses the built-in Jetty server, and when deployed to Tomcat Spark runs on Tomcat server.

Quoting from the documentation:

Other web server

To run Spark on a web server (instead of the embedded jetty server), an implementation of the interface spark.servlet.SparkApplication is needed. You have to initialize the routes in the init() method, and the following filter has to be configured in your web.xml:

...

So in order to run the same code after deployed to Tomcat, you need to:

  1. Your class should implement SparkApplication.
  2. Implement the init() method, and register all your routes there. (Of course, if you want to be able to run both locally on Eclipse and remotely on Tomcat, just register all your routes to some private method startSpark() which will be called both from init() and from main()).
  3. Your web.xml should be set accordingly.

这篇关于Spark休息api服务器部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆