- Java code (highest precedence)
- System property (e.g.
-Dmockserver.logLevel=DEBUG) - Property file (defaults to
mockserver.propertiesin the working directory) - Environment variable (lowest precedence)
Property file
By default MockServer looks for a file namedmockserver.properties in the current working directory. Override this location with the mockserver.propertyFile system property:
.properties format:
Key properties
Server port
Server port
The HTTP, HTTPS, SOCKS, and HTTP CONNECT port(s) for both mocking and proxying. Accepts a comma-separated list to listen on multiple ports.
| Value | |
|---|---|
| Default | (required — no default) |
| Type | int or comma-separated list |
Log level
Log level
The minimum level of logs to record in the event log and output to stdout. Lower log levels produce more output. The default is
INFO.Accepted values: TRACE, DEBUG, INFO, WARN, ERROR, OFF| Value | |
|---|---|
| Default | INFO |
| Type | string |
You can change the log level at any time without restarting MockServer.
Maximum expectations
Maximum expectations
The maximum number of expectations held in the in-memory ring buffer. When this limit is reached, the oldest expectations are overwritten.
| Value | |
|---|---|
| Default | free heap space in KB / 400 |
| Type | int |
Maximum log entries
Maximum log entries
The maximum number of log entries held in memory. This includes recorded requests, expectation match failures, and other log entries. Lower log levels produce more log entries, particularly at
TRACE.| Value | |
|---|---|
| Default | free heap space in KB / 30 |
| Type | int |
CORS allowed origins
CORS allowed origins
Controls the You can also customize the allowed headers and methods:
Access-Control-Allow-Origin header for CORS responses. Set enableCORSForAPI to allow cross-origin requests to the MockServer REST API, or enableCORSForAllResponses to enable CORS on all responses including expectation responses.Initialization JSON path
Initialization JSON path
The path to a JSON file used to pre-load expectations when MockServer starts. The file must contain a JSON array of expectations in the REST API format.
Enable
| Value | |
|---|---|
| Default | null |
| Type | string |
watchInitializationJson to have MockServer reload expectations automatically when the file changes:Programmatic configuration (Java)
When running MockServer in-process, set properties using the staticConfigurationProperties class or a per-instance Configuration object.
ConfigurationProperties is JVM-global and stores values as system properties:
Configuration is scoped to a single MockServer instance and is passed to the constructor:
Configuration falls back to ConfigurationProperties for any values you have not explicitly set.