Why am I not able to access the REST API exposed by my service?

Kaushik Mahadevan

I am trying to incorporate a few APIs into my existing spring-boot service, but I am not able to reach the APIs for some reason, when I try to access it from Postman.

Initially I thought it might be because of missing dependencies, so I added the spring-boot-started-web dependency to my build.gradle

classpath(group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.8.RELEASE')

My next troubleshooting steps involved checking the annotations of my app. After checking them, I could not find any issues.

This is the annotations of my config class:

@Configuration
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, RibbonAutoConfiguration.class})
@EnableScheduling
@ComponentScan({"com.example"})
@SpringBootApplication(exclude = { ErrorMvcAutoConfiguration.class })
public class MyApplication {
      // Some code
}

and this is my Controller class:

@RestController
public class MyApplication {

       @RequestMapping(method={RequestMethod.GET}, value="/myApi", produces=MediaType.APPLICATION_JSON_VALUE)
       public ResponseEntity<String> myApiHandler() {
           return new ResponseEntity<String>("Successfully called API", HttpStatus.OK);
       }
}

I had also defined the port in the application.properties file as follows:

server.port=6069

When I try to hit the following API from Postman, however, I am not able to get any response from the application:

localhost:6069/myApi

this is the error I get:

Error: connect ECONNREFUSED 127.0.0.1:6069

I am using Java 8, spring boot version 1.5.8 and Intellij IDE for development. Could you please let me know what I am missing? Any help is appreciated, thanks!

Udit Sharma

Use

@GetMapping("/myApi")

instead of

@RequestMapping(method={RequestMethod.GET}, value="/myApi", produces=MediaType.APPLICATION_JSON_VALUE)

This must resolve your issue.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why i am not getting the data in first call to my REST API

Why can't I Access a Service Exposed from Minikube on Windows?

Why I am able to access the users of a different tenant without adding any API permission to application in Azure Portal?

Why is woocommerce rest api not working? I am trying to access product details as json through woocommerce rest api

How am I able to access the Firebase variable AcX in my user?

Why is that I am able to access container outside the bridge network?

Why I am not able to access string individual chars using index

Why am I able to access file when device is locked? (iOS)

Why am I not able to access CSS properties with JavaScript?

Why I am not able to access xamarin elements in code behind in Forms

Why am I not able to access the result of multiple networking calls?

Why I am not able to access a value in the dictionary in C#?

Why am I getting 404 error Message "Not Found" on get request for my jersey rest service?

Why i am not able to call adapter method from my activity

Why am I not being able to insert values into my SQL database?

Why I am not able to receive data in my adapter

Why am I not being able to connect to my database?

Why am I able to instantiate my Abstract Base Class in Python?

Why I am not able to refer to my sequence with double quotes in postgres?

Why am i not able to push files into My Git Repo

Why am I not able to use promise in my basic react app?

Why am I not able oneHot encode my data labels?

Why i am not able to change the dummy variable here in my code?

Why am I not able to get proper dates in my graph?

Why am I not able to pickup items in my text based game?

Why am I not able to set cookies on my device?

I am not able access api's deployed in hostgator

Should my database be exposed by REST API

Why I am not able to fetch zebpay Api data?