编程语言
首页 > 编程语言> > java – Spark rest api服务器部署

java – Spark rest api服务器部署

作者:互联网

随着this link,我做了休息api服务器.当我运行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

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:

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

>您的类应该实现SparkApplication.
>实现init()方法,并在那里注册所有路由. (当然,如果您希望能够在Eclipse上本地运行并在Tomcat上远程运行,只需将所有路由注册到某个私有方法startSpark(),该方法将从init()和main()调用.
>应相应地设置您的web.xml.

标签:java,gradle,tomcat,spark-java
来源: https://codeday.me/bug/20190828/1753336.html