spring-bootloggingpropertiesyamlmockserver

How to set an environment variable in application.yml - Spring Boot


I'm working on a spring boot application and I'm writing some tests which use MockServer. In order to not have all the requests to the mock servers displayed in the logs, I have to set the environment variable mockserver.logLevel to OFF. When I do it via command line, it works perfectly :

mvn clean install -Dmockserver.logLevel="OFF"

but when I try to do it in my application.yml, it doesn't work. I've tried the following :

mockserver:
    log-level: OFF

mockserver:
    loglevel: OFF

mockserver:
    logLevel: OFF

logging:
  level:
    org.mockserver: OFF

But none of these work. I guess I don't write it correctly in the application.yml but I can't figure out the right way.


Solution

  • I finally found a way by adding it directly into the pom.xml as a system property variable in the concerned plugin :

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>${version.maven-failsafe-plugin}</version>
        <configuration>
            <systemPropertyVariables>
                <mockserver.logLevel>OFF</mockserver.logLevel>
            </systemPropertyVariables>
        </configuration>
    </plugin>