0

I tried to add ResponseEntity<> in my rest endpoint class(spring boot project), where it does not allow me to add and I got a compilation error as "ResponseEntity cannot be resolved to a type". Please let me know why I'm not able to add them into my project.

Also I would like to know the ways for handling http status codes in response?

Thanks in Advance!

Sharmila
  • 23
  • 1
  • 2
  • 6
  • Does this answer your question? [view cannot be resolved to a type](https://stackoverflow.com/questions/5512557/view-cannot-be-resolved-to-a-type) – lakshman Dec 31 '19 at 07:32

2 Answers2

1

How you init your ResponseEntity ?

You can do something like this :

ResponseEntity<String> responseEntity = new ResponseEntity<>(HttpStatus.OK);
Nick
  • 805
  • 5
  • 14
  • This will have no effect. Since the problem is during the compilation, this too will give the same error. The problem is dependencies are not present at compile time. – Aman jangra Dec 31 '19 at 07:34
  • Do you have annotation org.springframework.boot spring-boot-starter-web ? – Nick Dec 31 '19 at 07:36
  • I am not the one who asked the question – Aman jangra Dec 31 '19 at 07:40
  • These are my dependencies I have added and not able to resolve the problem – Sharmila Dec 31 '19 at 16:11
  • I have added spring-boot-starter-web,spring-boot-starter-jdbc,spring-boot-starter-parent and mysql-connector-java . though having these dependencies, it is still showing ResponseEntity and also jdbcTemplate cannot be resolved to a type . – Sharmila Dec 31 '19 at 16:17
0

You need to have

implementation 'org.springframework.boot:spring-boot-starter-web'

dependency in your build.gradle for including ResponseEntity<T>

Then, you can use it like

public ResponseEntity<String> getResponseEntityDemo(){
    return new ResponseEntity<>("This is the body", HttpStatus.OK);
}
Mohamed Anees A
  • 4,119
  • 1
  • 22
  • 35