HATEOAS methods not found

Solution 1:

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.

Solution 2:

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.*

Solution 3:

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 !!

Solution 4:

Add below dependency in pom.xml,it could resolve your issue.

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

If above doesn't work then easy solution is got with older versions of hateos.

As new versions of Hateoas has been changed totally, below link can help you. https://docs.spring.io/spring-hateoas/docs/current/reference/html/

Am mentioning some major changes in methods of Hateoas

ResourceSupport is now RepresentationModel

Resource is now EntityModel

Resources is now CollectionModel

PagedResources is now PagedModel

The LinkDiscoverer API has been moved to the client package.

The LinkBuilder and EntityLinks APIs have been moved to the server package.

ControllerLinkBuilder has been moved into server.mvc and deprecated to be replaced by WebMvcLinkBuilder.

RelProvider has been renamed to LinkRelationProvider and returns LinkRelation instances instead of Strings.

VndError has been moved to the mediatype.vnderror package

Solution 5:

There are some nomenclature changes in the recent release(2.2.0 or >). Refer to this document