0
votes

I’m trying to run a spring boot application. I downloaded a code from a tutorial so I know the code works. When I run my jar file, it looks like the applications I running on port 8080 but still I get 404 for any URL, I never got the spring white label page. I checked that I don’t have anything else running on port 8080, and the server I up and running.

I have no clue why my applications are not responding.

running the jar

error 404

package com.virtualpairprogrammers;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by masn on 2017-04-01.
*/

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String sayHello(){
        return "Hello";
    }
}


enter code here

package com.virtualpairprogrammers;

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication public class FleetmanApplication {

public static void main(String[] args) {
    SpringApplication.run(FleetmanApplication.class, args);
}

}

enter code here

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.virtualpairprogrammers</groupId>
<artifactId>fleetman</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>fleetman</name>
<description>VPP´s Fleet Management Application</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

2
Well at least I should get the whitelabel page? And yes I tried adding controllers.... - Mattias S. Nordell
sorry. check now, didnt do any setting, and follow a tutorial and it works in the video 100% same instructions. - Mattias S. Nordell
Well In the vidoe he clearly states that defaul is anyt request type and it works for him without any method stated. - Mattias S. Nordell
Added your suggetsion still the same problem - Mattias S. Nordell

2 Answers

1
votes

If you run the command java -jar YourAppName.jar you must be located inside the root folder (fleetman) and NOT INSIDE the target folder where the .jar is located. This is a common mistake so run the command inside the fleetman folder.

You might want to update the pom.xml with this

 <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <executable>true</executable>
        </configuration>
    </plugin>
0
votes

Just try like this and it will work:

@RestController
public class HelloController {

    @RequestMapping(path = "/hello", method = RequestMethod.GET)
    public String hello() {
        return "hello";
    }
}

Here's the screenshot I've taken from my computer: Working Controller