How to change the mongodb directories

  java

The library:

<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>3.2.8</version>
</dependency>

The error:

2022-08-05 22:42:21.848 ERROR 28436 --- [           main] d.f.e.process.runtime.AbstractProcess    : failed to call start()

java.io.IOException: Cannot run program "C:\Users\john\AppData\Local\Temp\extract-c78a98b2-5793-4427-aac9-5edc8dd55ff4extractmongod.exe": CreateProcess error=1260, This program is blocked by group policy. For more information, contact your system administrator
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143) ~[na:na]
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073) ~[na:na]
	at de.flapdoodle.embed.process.runtime.ProcessControl.start(ProcessControl.java:165) ~[de.flapdoodle.embed.process-3.1.6.jar:na]
	at de.flapdoodle.embed.process.runtime.AbstractProcess.<init>(AbstractProcess.java:96) ~[de.flapdoodle.embed.process-3.1.6.jar:na]
	at de.flapdoodle.embed.mongo.AbstractMongoProcess.<init>(AbstractMongoProcess.java:53) ~[de.flapdoodle.embed.mongo-3.2.8.jar:na]
	at de.flapdoodle.embed.mongo.MongodProcess.<init>(MongodProcess.java:50) ~[de.flapdoodle.embed.mongo-3.2.8.jar:na]
	at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:44) ~[de.flapdoodle.embed.mongo-3.2.8.jar:na]

The fix:

Create a new Java file:

import org.apache.commons.lang3.SystemUtils;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MongoConfig {

    public MongoConfig() {

        if (SystemUtils.IS_OS_WINDOWS) {
            System.setProperty("de.flapdoodle.embed.io.tmpdir", "c:\\temp\\mongotemp");
            System.setProperty("EMBEDDED_MONGO_ARTIFACTS", "c:\\temp\\mongoartifacts");
        }
    }
}

Create the 2 specified directories as well, c:\temp\mongotemp and c:\temp\mongoartifacts

Run the app.

In the c:\temp\mongotemp you will see the mongo executable that the system policy was blocking from running earlier on: