HATEOAS methods not found

In case you are using HATEOAS v1.0 and above (Spring boot >= 2.2.0), do note that the classnames have changed. Notably the below classes have been renamed:

  • ResourceSupport changed to RepresentationModel
  • Resource changed to EntityModel
  • Resources changed to CollectionModel
  • PagedResources changed to PagedModel
  • ResourceAssembler changed to RepresentationModelAssembler

More information available in the official documentation here.

When using Spring boot starter, the below dependency would suffice to include HATEOAS:

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

Hoping this information will help someone like me who searched for hours to find why Resource class was not getting resolved.


Looks like your POM is missing the spring-hateoas dependency.

So first add this to pom.xml:

<dependency>
    <groupId>org.springframework.hateoas</groupId>
    <artifactId>spring-hateoas</artifactId>
    <version>0.15.0.RELEASE</version>
</dependency>

Then you can add this static import and your code should compile:

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*

If you are using HATEOAS in eclipse(Version : Oxygen.3a Release (4.7.3a)), please note that the class names have changed.

Resource changed to EntityModel
Resources changed to CollectionModel

More information available in the official documentation below link ->

https://docs.spring.io/spring-hateoas/docs/current/reference/html/

When using Spring boot starter, you've to use below dependency to include HATEOAS:

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

Demo Code :

EntityModel<Users> resource = new EntityModel<Users>(user);
        ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers());
        resource.add(linkTo.withRel("all-users"));

Note : You have to import

import static org.springframework.hateoas.server.mvc.ControllerLinkBuilder.*;

Hope this information is helpful to find why Resource class was not getting resolved !!