I have a project with a Spring container. Let's say this project is called my-common-library
and uses the namespace my.common
. It scans all components in this namespace, as specified in common-context.xml
which looks like following
<beans ...>
<context:component-scan base-package="my.common"/>
</beans>
Among other things this scan detects classes annotated with @MyComponent
.
Now I would like to reuse this project as fully as possible. Let's say I start a new project my-client
which uses in the namespace my.client
. The my-client
mostly consists of components annotated with @MyComponent
.
In the ideal world I would just add the dependency my-common-library
and all @MyComponent
s will be scanned and registered. The only problem is the new namespace is unknown to the original my-common-library
.
One solution that I'm aware of is to add an updated common-context.xml
to my-client
which would look like
<beans ...>
<context:component-scan base-package="my.common,my.client"/>
</beans>
That would certainly work, but seems quite fragile. Is there a more elegant solution maybe?
@Import(MyCommonLibraryConfig.class)
with a custom annotation provided by MyCommonLibrary? (es. @MyCommonLibraryEnabled) – Adrenal