Mar*_*oli 5 java apache tomcat spark-java
我有一个Spark MVC应用程序,非常简单.
根据spark文档,这应该足以运行应用程序:
public class SparkServer {
public static void main(String args[]) {
Spark.staticFileLocation("src/main/webapp");
System.out
.println("bla bla bla");
RService rService = new SparqlRService();
new RController(rService);
}
}
Run Code Online (Sandbox Code Playgroud)
我将该类放在项目中的一个包中,然后在Apache Tomcat服务器上运行Web应用程序(动态Web应用程序).
运行Apache Tomcat时不会出现print语句,这意味着此类未被调用.我知道这很有道理.这就是我要问的原因.请问如何让Apache Tomcat运行我的spark应用程序?
之后@mlk答案,我做了以下内容:
public class SparkServer implements SparkApplication {
@Override
public void init() {
Spark.staticFileLocation("src/main/webapp");
System.out
.println("bla bla lba");
RService rService = new SparqlRService();
new RController(rService);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的web.xml中我做了:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>SRecommender</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>SparkFilter</filter-name>
<filter-class>spark.servlet.SparkFilter</filter-class>
<init-param>
<param-name>
applicationClass</param-name>
<param-value>com.srecommender.SparkServer</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SparkFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
我的SparkServer在一个包中:
com.recommender存在于源文件夹中:src/main/java
我运行apache tomcat,但是当我从spark调用任何路径时,它仍然返回404.
HITE我可以从main方法运行spark并调用我的页面,它们正在工作.所以我配置spark的方式问题在apache tomcat中运行
这是如何设置视图的路径
public RecommendationController(RecommendationService service) {
get("/", (request, response) -> {
Map<String, Object> model = new HashMap<>();
model.put("data", "forza ROMA");
model.put("data2", "It's Rome, It's home");
return View("src/main/webapp/template/index.html", model);
});
Run Code Online (Sandbox Code Playgroud)
WebApps 不执行static void main()方法,它们根据web.xml部署的 WAR 文件进行引导。
您有运行网络应用程序的经验吗?您需要一个像 Tomcat 或 Jetty 这样的容器。Apache 服务器仅用于提供 HTTP 服务,其本身并不是应用程序容器。
| 归档时间: |
|
| 查看次数: |
920 次 |
| 最近记录: |