After a lot of work and research, I noticed that Spring's behavior is a little strange in terms of component scanning.
The artifacts were as follows:
"ServiceImpl" is a real implementation class that implements the "Service" interface. "ServiceMockImpl" is a mock implantation class that implements the "Service" interface.
I would like to configure component scanning so that it only loads "ServiceMockImpl", but not "ServiceImpl".
I had to add "@ ComponentScan.Filter (type = FilterType.ASSIGNABLE_TYPE, value = ServiceImpl.class)" to the "@ComponentScan" class of the test configuration to exclude this particular class from component scanning. But both classes were loaded even after the above changes were made, and the tests failed.
After a lot of work and research, I found that "ServiceImpl" was loading due to another class that loaded and had "@ComponentScan" for all the packages on top of it. So I added code to exclude the Application class from component scanning as follows: "@ ComponentScan.Filter (type = FilterType.ASSIGNABLE_TYPE, value = Application.class)."
After that, he worked as expected.
Code as below
@ComponentScan(excludeFilters = { @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = OAuthCacheServiceImpl.class), @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = Application.class) }, basePackages = { "common", "adapter", "admin"})
I saw that many questions on scanning components have remained unanswered for a long time, so I thought to add this data, as this may help someone in the future.
NTN ...
source share