Moving files to src/main/resources from src/test/resources

478 views
Skip to first unread message

Kyle Shrader

unread,
Mar 8, 2022, 6:13:31 PM3/8/22
to wiremock-user
Hello,
I am running WireMock as a stand-alone server in Spring Boot on the main application and using @AutoConfigureWiremock on the main application class. I am currently using src/test/resources/__files to store my response files.

I would like to move my response files to src/main/resources/stubs/__files. I am trying to configure my application.yml to have the wiremock.server.files to be classpath:stubs/__files but I see WireMock still tries to load from src/test/resources/stubs/__files.

How can I specify the configuration such that WireMock will use the src/main/resources during development and the corresponding directory when packing the application as a jar?

Thank you,
Kyle Shrader

Kyle Shrader

unread,
Mar 8, 2022, 6:56:19 PM3/8/22
to wiremock-user
Question, does having the following prevent @AutoConfigureWiremock from loading the application properties, or are the configurations merged?

@Bean
public Options wireMockOptions() {
    return WireMockSpring.options().port(8080);
}

Kyle Shrader

unread,
Mar 8, 2022, 7:11:47 PM3/8/22
to wiremock-user
For anybody doing the following:

// ** application.yml ** //

spring:
  main:
    web-application-type: none
  application:
    name: App
wiremock:
  server:
    files: classpath:/__files
    stubs: classpath:/mappings

// ** Application.class ** //

    @SpringBootApplication
    @AutoConfigureWireMock()
    public class Application extends SpringBootServletInitializer {
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }

        @Bean
        public Options wireMockOptions() throws IOException {
            final WireMockConfiguration options = WireMockSpring.options();
            options.port(8080);
            return options;
        }
    }

You should note that the application properties "files" and "stubs" are not being set on the wiremock server, as you would expect from AutoConfigureWireMock.

Anyways, I've resolved the issue by reading the values from the configuration file manually, and adding them to my options object.

Thanks,
Kyle Shrader
Reply all
Reply to author
Forward
0 new messages