Search code examples
javaazure-cosmosdbspring-boot-testspring-expression-language

Cosmos DB Container Name with EL not resolving in SpringBootTest


@SpringBootTest(properties = {"spring.profiles.active=build"}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)`
@TestPropertySource(value = {"classpath:application-test.properties"})
@RunWith(SpringJUnit4ClassRunner.class)
@EnableAutoConfiguration

I have the annotations shown on my integration test. and the entity class is like below

@Container(containerName = "Statuses-${spring.profiles.active}")
public class MessageStatus implements Serializable

The container name is successfully created as Statuses-local in the local env and when running the spring boot app, but this is not able to resolve the EL on the cosmos DB container name when running tests. Instead, the container creates as Statuses-${spring.profile.active}.

Please help, I need this to run tests using the build profile and the container name correctly resolves the EL on it when running the SpringBoot app, BUT when running my integration tests, this is misbehaving. Anything I am missing?

UPDATE: I have

@SpringBootApplication
DependsOn("expressionResolver")

on the main application class

Furthermore, I have tried another alternative of getting the container name from a function in a bean, but this is again is trying to create the container name as the code to resolve the name...

@Container(containerName = "#{@MyBean.getMessageStatusContainerName()}")
public class MessageStatus implements Serializable

And this, again, works fine when running the SpringBoot App, but NOT when trying to run tests.


Solution

  • I had included the annotation

    @ContextConfiguration(classes = {TestContextConfig.class, MyClass1.class, MyClass2.class})
    

    On the Integration Test, whereas, I have @EnableAutoConfiguration already, and that setting was "not happy" on creating the Test Application Context such that some necessary beans would be missing, and the resolution of the EL was not working.

    SOLUTION: Removed the annotation: @ContextConfiguration(classes = and all worked like fire!