0

I have created simple spring Boot Application.I have tried so many times but each time it is throwing error:404 Error when I run this on Pivotal tc server.It would be really great if any one can help me this.I have created Controller class with Spring Boot Starter Class.Below the image for the Error I am getting.Pivotal Server is up and running at port 8082 but as soon as I enter /hello to localhost:8082,I am getting Error 404(I have shared image of Pivotal server too in the last).I have almost tried everything that is available on google.I am starter in Spring Boot and would really appreciate if any one can give suggestion to resolve this.I have also shared pom.xml.

404 Error Screenshot-->Error Image.

I am running this on pivotal tc server with url: http://localhost:8082/hello

Link to Pivotal Server url Screenshot--->Pivotal server with controller return url Image Pivotal server is up and running but as soon as I enter http://localhost:8082/hello, I am getting 404 error.Can anyone please help.I have tried everything that I can search for.

Link to Pivotal server up and Running Screenshot-->Pivotal server up and running image

Code for Spring Boot Starter Class:

package io.javabrains.springbootstarter;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication   

public class CourseApiApp {

public static void main(String[] args) {

    SpringApplication.run(CourseApiApp.class,args);

 }

}

Code For controller Class:

package io.javabrains.springbootstarter.hello;

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

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

@RestController

public class HelloController {

@RequestMapping("/hello")

public String sayHi()
{
    return("Hello");
}
}

Pom.xml:

<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>io.javacheck.springbootquickstart</groupId>
<artifactId>course-api-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Java Brains Course Api</name>

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

<dependencies>

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

      <properties>
    <java.version>1.8</java.version>
</properties>

</project>
As1989
  • 3
  • 1
  • 4
  • Are you sure the server is running on port 8082? – Raziel25 Apr 30 '20 at 19:34
  • Yeah it is running at 8082.As soon as I enter /hello to localhost:8082,I am getting Error 404..I have shared the image also by name-->"Pivotal server up and running image" . – As1989 Apr 30 '20 at 19:43
  • Did you check the console output? – Raziel25 Apr 30 '20 at 19:50
  • 1
    check this [https://stackoverflow.com/questions/27211048/using-spring-boot-web-application-with-pivotal-tc-server](https://stackoverflow.com/questions/27211048/using-spring-boot-web-application-with-pivotal-tc-server) – Ryan Guamos Apr 30 '20 at 19:50
  • Yeah: Console Output---->May 01, 2020 12:56:28 AM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 1489 ms May 01, 2020 12:56:31 AM org.apache.catalina.startup.Catalina start INFO: Server startup in 3267 ms – As1989 Apr 30 '20 at 19:51
  • Can you test with `http://localhost:8082//hello`? – kayvis Apr 30 '20 at 19:56
  • I tried ,still not working. – As1989 Apr 30 '20 at 19:56
  • Tried for --->http://localhost:8082/course-api-test-0.0.1-SNAPSHOT/hello still getting the 404 error. – As1989 Apr 30 '20 at 19:57
  • 1
    Do you have a Tomcat Manager running in http://localhost:8082/manager? Are you able to see if you're app is deployed? You'll see a similar message in your server startup logs saying if the app has been deployed or not. – kayvis Apr 30 '20 at 19:59
  • Is that possible if you can take the code and run in you SpringBoot With Pivotal Server Or any suggestions to work this code? – As1989 Apr 30 '20 at 20:00
  • Do you have the code in Github? – kayvis Apr 30 '20 at 20:01
  • Can you post the server startup logs? Because it should say ' deployed successfully' or something along those lines. Given that you're getting 404, I'm not sure if your app is deployed or if we're accessing the wrong url. That's why I asked if you have a manager panel to see the list of running apps or the server startup logs to see what has been deployed. – kayvis Apr 30 '20 at 20:03
  • Could you please check this image url: https://i.stack.imgur.com/Kf0Bi.png .When i tried accesing localhost:8082/manager,It was asking for id and password and I dont have admin rights in my laptop. – As1989 Apr 30 '20 at 20:06
  • The username and password is for the Tomcat Server. Under your Tomcat server's installation directory you'll have conf/tomcat-users.xml. You can add the admin user and password there to access the Manager UI. Would you be able to edit that file? If so, I can provide the details. – kayvis Apr 30 '20 at 20:10
  • Actually I dont have tomcat installed.I using that configured pivotal tc in Spring Suite.Am I doing any thing wrong?I will push the code to git – As1989 Apr 30 '20 at 20:18
  • I'm not sure how you're deploying to the server. Can you push the code to Github and I'll take a look? Do you have to download anything for the Pivotal TC server? – kayvis Apr 30 '20 at 20:21
  • Pivotal TC server is already Configured with STS suite.You can RC on Project and Select RunAs-->RunOn Server – As1989 Apr 30 '20 at 20:37
  • Sure. Give me the Github url for your code and I'll try and take a look. – kayvis Apr 30 '20 at 20:42
  • Sorry I am not able to Push the code.I have just created the maven project and Added CourseApiApp and HelloController and pom.xml.Is tat possible for you to recreate? – As1989 Apr 30 '20 at 20:48
  • @kayvis--I am sharing the Manager the data from localhost:8082/manager: List Applications HTML Manager Help Manager Help Server Status Applications Path Version Display Name Running Sessions Commands / None specified Welcome to Tomcat true 0 Start with idle ≥ 30 minutes /course-api-test-0.0.1-SNAPSHOT None specified false 0 Stop Reload /docs None specified Tomcat Documentation true 0 Start with idle ≥ – As1989 May 02 '20 at 06:04

2 Answers2

0

use this :

@RestController
@RequestMapping("/test")
public class HelloController {

@GetMapping("/hello")
public String sayHi()
{
    return("Hello");
}
}

and then send a request to this API /test/hello

Amir Pezeshk
  • 359
  • 1
  • 5
0

Could you try wrapping the String inside Response Entity.

@RestController
public class HelloController {

 @RequestMapping("/hello")
 public ResponseEntity<String> sayHi()
 {
   return ResponseEntity.ok("Hello");
 }
}
Mamtha Soni K
  • 895
  • 6
  • 9