HAL Setting in Spring hateoas

If not setting spring hateoas hal

Spring Hateoas project is a amazing project to make hateoas project very easy. However, if we don’t tell spring hateoas which style we want to use. it would not provide consistent style. I found that in my recent project. It is a wired bug. Because I always expect HAL style when I code in React project.

How to

To tell spring hateoas your setting, we should add this annotation.

@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)

Here is a more complete application setting.

package au.com.othera.accountservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.hateoas.config.EnableHypermediaSupport;
import org.springframework.scheduling.annotation.EnableAsync;

import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableSwagger2
@EnableAsync
@EnableScheduling
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
public class xxx {
    public static void main(String[] args) {
        SpringApplication.run(AccountServiceApplication.class, args);
    } 
}

Leave me a message

comments powered by Disqus

Published

Category

Spring

Tags