I implemented a custom EnvironmentRepository, but when I start the microservice the latter crashes with an error: "Invalid config server configuration."
Develop Kit: - Java version 17 - Spring version 2.7.3 - Spring Cloud version 2021.0.4
application.yml:
spring:
application:
name: "confserver"
profiles:
active: "runtime"
Main.kt:
@EnableConfigServer
@SpringBootApplication
class ConfigMicroserviceApplication
fun main(args: Array<String>) {
runApplication<ConfigMicroserviceApplication>(*args)
}
RuntimeEnvConfig.kt:
@Configuration
@Profile("runtime")
class RuntimeEnvConfig {
@Bean
@ConditionalOnMissingBean(RuntimeEnvironmentRepository::class)
fun runtimeEnvironmentRepository(): RuntimeEnvironmentRepository = RuntimeEnvironmentRepository()
}
RuntimeEnvironmentRepository.kt:
class RuntimeEnvironmentRepository : EnvironmentRepository, Ordered {
private val logger: Logger by lazy { LoggerFactory.getLogger(this::class.java) }
init {
logger.info("INIT")
}
override fun getOrder(): Int = Ordered.LOWEST_PRECEDENCE
override fun findOne(application: String, profile: String, label: String) =
Environment(application, profile).apply {
logger.info("Arguments", "${application} - ${profile} - ${label}")
add(
PropertySource("RuntimePropertySource", mapOf(Pair("key1", "value1")))
)
}
}
Console output:
2022-09-18 12:20:50.744 WARN 2949 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthContributorRegistry' parameter 2; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'configServerHealthIndicator' defined in class path resource [org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration$ConfigServerActuatorConfiguration.class]: Unsatisfied dependency expressed through method 'configServerHealthIndicator' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'searchPathCompositeEnvironmentRepository' defined in class path resource [org/springframework/cloud/config/server/config/CompositeConfiguration.class]: Unsatisfied dependency expressed through method 'searchPathCompositeEnvironmentRepository' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultEnvironmentRepository' defined in class path resource [org/springframework/cloud/config/server/config/DefaultRepositoryConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: You need to configure a uri for the git repository.
2022-09-18 12:20:50.753 INFO 2949 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-09-18 12:20:50.791 INFO 2949 --- [ main] ConditionEvaluationReportLoggingListener :
***************************
APPLICATION FAILED TO START
***************************
Description:
Invalid config server configuration.
Action:
If you are using the git profile, you need to set a Git URI in your configuration. If you have set spring.cloud.config.server.bootstrap=true, you need to use a composite configuration.
Disconnected from the target VM, address: '127.0.0.1:54141', transport: 'socket'
Process finished with exit code 1