Let's say I have a service interface com.example.Service
.
For a test, I defined a
src/test/resources/META-INF/services/com.example.Service
file which contains
com.example.sometest.MockServiceImpl
the MockServiceImpl
implements the interface.
Now, when doing a ServiceLoader.load(Service.class)
and iterating over the result, my MockServiceImpl
is always instantiated again. The javadoc for ServiceLoader
states that it DOES maintain a cache, but my mock service does not seem to be cached.
Why is that so, and how do I get the ServiceLoader
to cache it?