I was wishing to wrap my controller calls for rest api testing for handy usage and wrote
class BaseControllerWrapper { @LocalServerPort int port; ...}@Componentclass SpecificControllerWrapper extends BaseControllerWrapper { void callEndpoint() { ... }}@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)public class PermissionsTest { @Autowire SpecificControllerWrapper specificControllerWrapper; @Test public void testSomething() { ... wrapper.callEndpoint(); ... }}Unfortunately, Spring was unable to instantiate beans with
Error creating bean with name 'specificControllerWrapper': Injection of autowireddependencies failed; nested exception isjava.lang.IllegalArgumentException: Could not resolve placeholder'local.server.port' in value "${local.server.port}" atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:405)
Is it possible to overcome?