我有一些非常简单的代码,目前正在尝试让this开始启动并运行Spark项目。
我的代码如下所示:
import static spark.Spark.*;
public class Main {
public static void main(String[] args) {
get("/hello", (req, res) -> "Hello World");
}
}
我在运行http://localhost:4567/hello
时遇到此错误localhost refused to connect.
ERR_CONNECTION_REFUSED
如果需要,还可以使用pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
答案 0 :(得分:0)
试试这个:
import static spark.Spark.*;
public class Main {
private static final int PORT = 8080; // or other not taken port
public static void main(String[] args) {
port(PORT);
get("/hello", (req, res) -> "Hello World");
}
}
如果这有助于尝试关闭防火墙一段时间,可能会有所帮助。