I came up with the following solution (for questions No. 2 and No. 3) in order to be able to apply my design recommendations and continue to use the configuration based on annotations:
- Each dependent project (Maven module) has its own
ApplicationContext - Each dependent context of a project application is defined in
beanRefContext.xml - These application contexts are loaded into the hierarchy using the Spring context hierarchy mechanism.
- This step is actually not fully supported by Spring and requires additional work.
- Since my application is multi-level, I can disable CGLib in all my modules except for the JMX level (I can live with it :-)).
The above steps also allowed me to reduce the execution time of Spring tests (each module is loaded only with a subset of beans).
As a practical guide (for question number 1), if the interface has more than one implementation, I place @Primary on the widely used one and the other clients, requiring a different implementation, conducting a bean using @Qualifier .
source share