Philipp Mayer
01/06/2021, 8:46 PM@Configuration
class?
Usually, one would define it as follows:
@ConstructorBinding
@ConfigurationProperties(prefix = "rooms")
class RoomConfigurationProperties(val filePath: String)
But due to modularization, I have a configuration class for the whole module (speak: maven module) whichs looks similiar to that:
@Configuration
@ComponentScan
class RoomConfig {
@Bean
@ConfigurationProperties(prefix = "rooms")
fun properties(filePath: String) = RoomConfigurationProperties(filePath)
/*...*/
}
However, since the filepath is a constructor parameter, I of course have to supply it and I'm not sure how. Any hint would be appreciated, I unfortunately didn't find what I was looking for in the docs.kqr
01/06/2021, 8:58 PMkqr
01/06/2021, 8:59 PMPhilipp Mayer
01/06/2021, 9:23 PMmodule1
, module2
and configuration
, where the latter holds the applications main class.
After reading about (https://reflectoring.io/testing-verticals-and-layers-spring-boot/) how to properly test the modules without having a dependency on configuration (since config has a dependency on the other modules -> would be circular)
I decided to have a configuration class per module which holds the info, so I can pass that class later on in my apps main class and to also use that class in my tests:
@SpringBootTest(classes = [Module1Config::class], webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Since Module1Config
holds all info, it also needs the `Module1ConfigurationProperties`` Bean to pass it into the other services.
Problem there is that I have to provide the constructor arguments for my ConfigurationProperties (see message 1) and I fail to achieve that.
That turned out to be longer than expected. Hit me up if it is too blurry.Philipp Mayer
01/06/2021, 9:26 PMSaharath Kleips
01/06/2021, 9:47 PM@ExtendWith(SpringExtension::class)
@ContextConfiguration(initializers = [ConfigDataApplicationContextInitializer::class])
class MyTest { ... }
The SpringExtension
will integrate a Spring TestContext and the ContextConfiguration
will let you load config properties. Then you could just perhaps @Import
your RoomConfig
or whatever else you need?kqr
01/06/2021, 9:49 PMkqr
01/06/2021, 9:50 PM@Bean
fun someBean(roomConfigurationProperties:RoomConfigurationProperties): SomeBean {...}
Philipp Mayer
01/06/2021, 9:54 PM@SpringBootTest
.kqr
01/06/2021, 9:56 PMkqr
01/06/2021, 9:57 PMPhilipp Mayer
01/06/2021, 9:58 PMPhilipp Mayer
01/06/2021, 10:17 PMkqr
01/06/2021, 11:30 PM