Skip to content

How to call class from another module in SpringBoot, Java

I have a Spring Boot multi-module gradle project, and I am trying to call class from another module. I have a class that I would like to call in class in another module.

public class HttpDataClient implements DataClient{

    private final static Logger LOGGER = LoggerFactory.getLogger(HttpDataClient.class);

    private final RestTemplate restTemplate;
    private final ObjectMapper objectMapper = new ObjectMapper();

    public HttpDataClient(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;

    public DataResponse getData(String dataId) {
            JsonNode node =
                    String.format("/data/%s", dataId),
                    new HttpEntity<>(buildRequest(dataId), headers()),
            return dataResponse(node);
        }catch (HttpStatusCodeException e) {
            String msg = String.format(
                    "Error getting data for dataId: %s",
            return dataResponse.failed();

    private MultiValueMap<String, String> headers() {
        final LinkedMultiValueMap<String, String> mv = new LinkedMultiValueMap<>();
        mv.set(HttpHeaders.CONTENT_TYPE, "application/json");
        return mv;

    private DataResponse dataResponse(JsonNode node) {
        return DataResponse.dataResponse(
                asString(node, "dataId"),
                asString(node, "dataAuthor"),
                asString(node, "dataAuthorId")

    private JsonNode buildRequest(String dataId) {
        ObjectNode root = objectMapper.createObjectNode();
        root.put("dataId", dataId);
        return root;

So, this class should return some response data from Data service. After I would like to get that response data and do something in class in other module.

I am trying to do it like this:

public class DataResolver {

    private final HttpDataClient client;

    public DataResolver(HttpDataClient client) {
        this.client = client;

But my HttpGameDataClient class that I am trying to use it is not recognized by class.

What am I missing here? Any advice is appreciated.



Be sure the module you need is put as a dependency to the module who need it.