We've built a Spring service discovery solution that autowires several local classes annotated with @Component
or @Service
through a component scan at the root package level via @SpringBootApplication
. The project follows a standard maven/spring layout:
project
src/main/java
service
- ServiceA.java
- ServiceB.java
...
model
- modelA.java
...
component
- ComponentA.java
- ComponentB.java
BootApp.java
pom.xml
We'd like to now distribute this internally as a library, and doing so requires a spring.factories
file (see how marathon does it / see spring autoconfig docs). Looking at other service-discovery implementations like marathon
and eureka
, it appears that I should remove all autowiring annotations (ie. @Component
and @Service
) and instead manually configure all of the components/beans into one or more @Configuration
classes. The app is already autowiring and bootstrapping over ten classes- I'd prefer to not have to refactor and manually wire these up.
My question: is there any way to simply retain the existing autowiring/project structure and have spring.factories
pick it up in something similar to a component scan? Something like:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=project.BootApp
or
org.springframework.boot.autoconfigure.EnableAutoConfiguration=project.*
Are there any other tips or best practices on how refactor to support spring.factories
without having a massive @Configuration
class? Is it possible to split the difference and have most of our internal objects autowired but then manually configure public objects like DiscoveryClient
and ServiceRegistery
(see spring cloud SPI) and reference them in spring.factories
?