0

I have a following controller in my microservices-core project:

package com.XYZ.microservices.core.api.version;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/version")
public class VersionController {

    @Autowired
    private VersionService versionService;

    @RequestMapping(method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
    public Version getVersion() {
        return versionService.getVersion();
    }
}

I have another project called product-service. I am importing microservices-core to product-service like this:

dependencies {
        compile("com.XYZ:microservices-core:1.0.0-RELEASE")
        ...
}

Now, I am initializing product-service application like this:

@SpringBootApplication
public class ProductServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProductServiceApplication.class, args);
    }
}

The classes in microservices-core are available in product-service. But I am not able to GET localhost:8080/version when I run product-service. Can someone help?

3
  • What's the error you are getting ? 404 ? Commented Dec 8, 2016 at 1:47
  • yeah, whitelabel error page Commented Dec 8, 2016 at 2:00
  • Can you add the spring trace that you see on the output when you start the application? Commented Dec 8, 2016 at 2:48

1 Answer 1

3

My guess is your main application class package is not in the same package as the controller class.

Add ComponentScan annotation to your main class to scan all subpackages for components:

@SpringBootApplication
@ComponentScan({"com.XYZ.microservices.core"})
public class ProductServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProductServiceApplication.class, args);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

that does it. Thank you very much sir! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.