0

If I want to use my own own spring boot project as a dependency to other spring boot projects. But without component scan my dependency rest end points are not exposed . How to expose my dependency rest end points automatically like actuator when it is added to dependency.

<dependency>
            <groupId>com.sapient.asde.batch5</groupId>
            <artifactId>vehicle-data-service</artifactId>
            <version>0.0.1-SNAPSHOT</version>
</dependency>

Given I pushed my project to local repo and add the above dependency

@ComponentScan(basepackages={"somepackage"})

Without ComponentScan in the dependency added project rest end points are not visible.How to automate this

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
  • It's not a good idea to post [images in place of code](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question#:~:text=Images%20are%20often%20blocked%20by,t%20useful%20to%20future%20readers.) – DCTID Aug 12 '21 at 02:19
  • Ok , thanks for the information , I changed the post. – muth arasan Aug 12 '21 at 03:15

1 Answers1

0

You don't really require to add another spring boot project in case you specifically expect the IOC feature for the classes present in the classpath, simple add the controllers in the dependency projects and make that particular package that contains the controller classes comes under the component scan vision, then the controller will be automatically registered with the Spring container for application use.

Prasanth Rajendran
  • 4,570
  • 2
  • 42
  • 59
  • Thanks bro , but with the component scan added to your base project the rest controller will be exposed automatically, but in the case of actuator if you add that you don't need to add that actuator package in your application it will automatically expose some rest end points.My project is exposing end points to other project but without component scan , the rest end points are not exposed but I want to know how to automate this without even adding component scan my project should expose some rest end points automatically like actuator. – muth arasan Aug 14 '21 at 15:08
  • Under the hood, Spring-boot does plenty of BlackBox tasks to autoconfigure the Actuator if actuator-starter dependency is present in the classpath, likewise, if you want to replicate the same behavior with your custom controller there is no other way apart from exposing the rest controller to the spring container, but there are some tricks for your use case like adding `@profile()` on top of your controller or condition-based handler mapping using `@ConditionalOnExpression("${my.controller.enabled:false}")`, you can also refer the [answer] (https://stackoverflow.com/a/29958374/3303074) – Prasanth Rajendran Aug 15 '21 at 17:04
  • Thank you for the response, I'll try this. – muth arasan Aug 16 '21 at 04:54