In MockServer expectations are only held in memory by default. However, it is possible to persist expectations to the local file system to ensure that they survive a restart of MockServer.

  1. persistExpectations configuration property needs to be set to true
  2. the file path used to persist expectations can be configured using the persistedExpectationsPath configuration property
  3. expectations should be initialised automatically using the initializationJsonPath configuration property

To ensure that the persisted expectations are loaded the next time MockServer starts the initializationJsonPath and persistedExpectationsPath should match and the persistExpectations should be set to true as follows:

MOCKSERVER_INITIALIZATION_JSON_PATH=mockserverInitialization.json \
java -jar ~/Downloads/mockserver-netty-5.8.0-jar-with-dependencies.jar -serverPort 1080,1081 -logLevel INFO


java \
-Dmockserver.persistExpectations=true \
-Dmockserver.persistedExpectationsPath=mockserverInitialization.json \
-Dmockserver.initializationJsonPath=mockserverInitialization.json \
-jar ~/Downloads/mockserver-netty-5.8.0-jar-with-dependencies.jar -serverPort 1080,1081 -logLevel INFO