Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run WireMock Server as a SpringBoot application

I am new to WireMock framework. My request is to run WireMock as a server that can accept stubs on a Spring Boot application. I tried to use the Spring Cloud Contract dependency but that only helps me in running the tests. Any direction or samples would be greatly helpful in this regard.

like image 463
Sundar Avatar asked Oct 18 '25 00:10

Sundar


1 Answers

The main crux is to make the spring web-application-type: none in application.yml file. So that when the Spring Boot application is started from IDE it runs Wiremock on http port 8080 which internally runs on jetty server

Below is the appplication.yml file


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

Below is SpringBoot Application class

    @SpringBootApplication
    @Slf4j
    @AutoConfigureWireMock
    public class Application extends SpringBootServletInitializer {
       
    
        public static void main(String[] args) {
            log.info("Starting  Application");
            SpringApplication.run(Application.class, args);
        }
    
       
    
        @Bean
        public Options wireMockOptions() throws IOException {
    
            final WireMockConfiguration options = WireMockSpring.options();
            options.port(8080);
            
            return options;
        }
    
    
    
    }

Please make sure you have these dependencies

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-contract-wiremock</artifactId>
</dependency>
like image 121
techiesantosh Avatar answered Oct 20 '25 15:10

techiesantosh