33import  org .springframework .boot .test .context .TestConfiguration ;
44import  org .springframework .boot .testcontainers .service .connection .ServiceConnection ;
55import  org .springframework .context .annotation .Bean ;
6+ import  org .springframework .test .context .DynamicPropertyRegistrar ;
67import  org .springframework .test .context .DynamicPropertyRegistry ;
78import  org .testcontainers .containers .GenericContainer ;
89import  org .testcontainers .containers .PostgreSQLContainer ;
1213@ TestConfiguration (proxyBeanMethods  = false )
1314public  class  TestcontainersConfig  {
1415
16+     @ Bean 
17+     public  DynamicPropertyRegistrar  propertiesOverride (GenericContainer  wiremockContainer ) {
18+         return  (registry ) ->
19+             registry .add ("http.exchange-client.url" , () -> httpUrl (wiremockContainer , 8080 ));
20+ 
21+     }
22+ 
1523    @ Bean 
1624    @ ServiceConnection 
1725    public  PostgreSQLContainer  postgreSQLContainer () {
@@ -23,22 +31,21 @@ public PostgreSQLContainer postgreSQLContainer() {
2331    }
2432
2533    @ Bean 
26-     public  GenericContainer  wiremockContainer (DynamicPropertyRegistry   registry ) {
27-         var   container  =  new  GenericContainer ("wiremock/wiremock:3.0.0-1" )
34+     public  GenericContainer  wiremockContainer () {
35+         return  new  GenericContainer ("wiremock/wiremock:3.0.0-1" )
2836            .withExposedPorts (8080 )
2937            .withCopyFileToContainer (MountableFile .forClasspathResource ("stubs" ), "/home/wiremock" )
3038            .waitingFor (Wait 
3139                .forHttp ("/__admin/mappings" )
3240                .withMethod ("GET" )
3341                .forStatusCode (200 ));
34- 
35- 
36-         registry .add ("http.exchange-client.url" , () -> httpUrl (container .getHost (), container .getMappedPort (8080 )));
37- 
38-         return  container ;
3942    }
4043
4144    private  static  String  httpUrl (String  host , Integer  port ) {
4245        return  String .format ("http://%s:%d" , host , port );
4346    }
47+ 
48+     private  static  String  httpUrl (GenericContainer  container , Integer  originalPort ) {
49+         return  httpUrl (container .getHost (), container .getMappedPort (originalPort ));
50+     }
4451}
0 commit comments