最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring boot - @RestartScope doesn't preserve properties in SpringBoot application - Stack Overflow

programmeradmin0浏览0评论

I am using a following class:

@TestConfiguration(proxyBeanMethods = false)
class TestContainersConfiguration {

    private val logger = LoggerFactory.getLogger(TestContainersConfiguration::class.java)

    @Bean
    @RestartScope
    fun keycloakContainer(registry: DynamicPropertyRegistry): KeycloakContainer? {

        val keycloak: KeycloakContainer? = KeycloakContainer("quay.io/keycloak/keycloak:24.0.2")
            .withEnv("DB_VENDOR", "h2")
            .withAdminUsername("admin")
            .withAdminPassword("admin")
            .withContextPath("/auth")
            .withRealmImportFile("/simple-application-realm.json")
            .withLogConsumer(Slf4jLogConsumer(logger))

        registry.add(
            "spring.security.oauth2.resourceserver.jwt.issuer-uri"
        ) { keycloak?.authServerUrl + "/realms/simple-application-realm" }

        registry.add(
            "spring.security.oauth2.client.provider.keycloak.token-uri"
        ) { keycloak?.authServerUrl + "/realms/simple-application-realm/protocol/openid-connect/token" }

        registry.add(
            "spring.security.oauth2.client.registration.keycloak.client-id"
        ) { CLENT_ID }

        registry.add(
            "spring.security.oauth2.client.registration.keycloak.client-secret"
        ) { CLIENT_SECRET }

        return keycloak
    }

as configuration for my spring boot application:

fun main(args: Array<String>) {
    fromApplication<KotlinSimpleServiceApplication>().with(TestContainersConfiguration::class).run(*args)
}

The problem which I have is that when the application is being restarted then SpringBoot complains:

Could not resolve placeholder 'spring.security.oauth2.resourceserver.jwt.issuer-uri' in value "${spring.security.oauth2.resourceserver.jwt.issuer-uri}"

This is because the code for bean creation marked as @RestartScope is not executed so the property spring.security.oauth2.resourceserver.jwt.issuer-uri was not set.

I was experimenting with an idea to make the containers static and usage of System.setProperty, but I encountered a problem with hot swap saying operation not supported by vm schema change not implemented.

Is there any other way that I could set the properties which are utilized later by the application?

发布评论

评论列表(0)

  1. 暂无评论