有没有办法在运行时 spring 启动时更改 application.properties 中的某些 属性?
Is there a way to change certain property in application.properties in runtime spring boot?
我正在使用 testcontainers 来测试我的 API。
因为testcontainers不允许指定testcontainer的端口,我必须在创建testcontainers后连接到一些随机端口。
有没有办法在测试运行时重新加载 application.properties 或更改数据库端口?
我正在使用 mongodb、spring boot、kotlin、testcontainers。
提前致谢。
有几种方法可以连接到容器:
-
Testcontainers 允许在容器上 运行 container.getJdbcUrl()
,
但是,如果您想使用 Spring 引导自动配置而不是
手动创建连接,那么你可以使用
@DynamicPropertySource
所描述的注释 here
我正在使用 testcontainers 来测试我的 API。
因为testcontainers不允许指定testcontainer的端口,我必须在创建testcontainers后连接到一些随机端口。
有没有办法在测试运行时重新加载 application.properties 或更改数据库端口?
我正在使用 mongodb、spring boot、kotlin、testcontainers。
提前致谢。
有几种方法可以连接到容器:
Testcontainers 允许在容器上 运行
container.getJdbcUrl()
, 但是,如果您想使用 Spring 引导自动配置而不是 手动创建连接,那么你可以使用@DynamicPropertySource
所描述的注释 here