I am encountering the following issue:
When using Java 8 + Spring, I have the following code:
@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
SecurityUtilsBase.extractNativeLibraries("/usr/lib");
}
}
and
@PostMapping("/decrypt")
public String decrypt(@RequestParam String value) {
try {
TestCrypt crypt = new TestCrypt();
return crypt.cypher_Damo_Decrypt_B64(value);
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
The library loading in TestCrypt:
static {
try {
System.out.println("Before System.loadLibrary..");
System.loadLibrary("testcryptjni");
} catch (UnsatisfiedLinkError var1) {
System.out.println("libmascryptjni.so load error " + var1);
}
}
In this case, the controller doesn’t work at all, and the program stops immediately without any error message.
Stop app image
When I modify the main method and call it once before, like this:
@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
SecurityUtilsBase.extractNativeLibraries("/usr/lib");
TestCrypt crypt = new TestCrypt();
System.out.println(crypt.cypher_Damo_Decrypt_B64("0hKybskMef8voU8QHxQhww=="));
}
}
The controller then works normally. I suspect this is related to Java’s resource cleanup mechanism.
In Java 11, there is no way for this library to work. Why is that?
I tried to enable JNI logging, but it didn’t work
JNI log
manhpd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
6