Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4806

Is it possible to autowire local server port outside of a test class in Spring Boot test?

$
0
0

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?


Viewing all articles
Browse latest Browse all 4806

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>