Anil Mullamuri
02/04/2025, 11:08 AM@Configuration
public class WireMockConfig {
private WireMockServer wireMockServer;
@Value("${wiremock.root.directory}")
private String rootDirectory;
@Value("${wiremock.port}")
private String wiremockPort;
@EventListener(ApplicationReadyEvent.class)
public void startWireMockServer(){
wireMockServer = new WireMockServer(
WireMockConfiguration.options()
.port(Integer.parseInt(wiremockPort))
.withRootDirectory(rootDirectory)
.notifier(new ConsoleNotifier(true))
);
wireMockServer.start();
System.out.println("WireMock server started on port " + wiremockPort);
}
@Bean
public WireMock wireMock() {
WireMock.configureFor("localhost", Integer.parseInt(wiremockPort));
return new WireMock();
}
@EventListener(ContextClosedEvent.class)
public void stopWireMockServer() {
if(null != wireMockServer){
wireMockServer.stop();
System.out.println("WireMock server stopped");
}
}
}
rootDirectory - is the path of mapping parent folder,
So, i want to categorize the mappings inside mappings folder like Dev/ Stage/ Test.
Is it possible and howLee Turner
02/04/2025, 12:17 PMmappings
folder and I don't think it will allow categorisation of those files.
Could you do this by configuring the WireMock root directory via spring so it is configured per environment? I think you should be able to configure different properties for different environments in Spring boot. By doing that, you can have a different root directory per environment:
• /test/resources/dev/wiremock
• /test/resources/test/wiremock
• /test/resources/stage/wiremock
Each of the above folders will have a mappings directory wit the mapping files specific to that environment?Anil Mullamuri
02/04/2025, 2:20 PMAnil Mullamuri
02/04/2025, 2:22 PMLee Turner
02/05/2025, 7:24 AMMappingsLoaderExtension
that you could implement to achieve this - https://wiremock.org/docs/extensibility/adding-mappings-loader/Anil Mullamuri
02/05/2025, 10:20 AM