Alexander
Alexander

Reputation: 21

localhost refused to connect with Intellij Maven project

I have some really simple code and am currently trying to get this beginning Spark project up and running.

My code looks like this:

import static spark.Spark.*;

public class Main {
    public static void main(String[] args) {
        get("/hello", (req, res) -> "Hello World");
    }
}

and I get an this error when I go to run http://localhost:4567/hello

localhost refused to connect.
ERR_CONNECTION_REFUSED

Also the pom.xml file if needed

<?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>

Upvotes: 2

Views: 2247

Answers (1)

ulou
ulou

Reputation: 5863

Try this:

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");
    }
}

If this won't help try to turn off your firewall for a while, it might help.

Upvotes: 1

Related Questions