admin管理员组

文章数量:1122832

I have a Spring Boot application where I am using System.loadLibrary() to load a native DLL for a receipt printer service. Everything works perfectly fine until I add spring-boot-devtools as a dependency to enable hot reloading. Once I add DevTools, the library fails to load, and my application encounters errors when trying to use the service. I get this error exception:

java.lang.UnsatisfiedLinkError: 'int net.jposprinter.printerio.IOPort.nativeOpenPort(int, byte[], int)'

Here’s a simplified version of my setup:

@Service
public class ReceiptPrinterService {

    @Value("${dll.path}")
    private String dllPath;

    @PostConstruct
    public void loadDll() {
        try {
            System.loadLibrary(dllPath);
        } catch (UnsatisfiedLinkError e) {
            System.out.println("Error loading DLL: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public String printReceipt(String message) {
        // Logic to interact with the receipt printer...
    }
}

dependency added:

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
</dependency>

I tried adding this to application.properties:

spring.devtools.restart.exclude=resources/libs/**,resources/jpos.xml

but still didn't work (the dll is in libs directory)

What I Need:

  1. Why does adding Spring DevTools interfere with loading native DLLs?

  2. What is the best way to configure Spring DevTools to avoid this issue while keeping the hot reload functionality for the rest of the application?

  3. Are there alternative approaches to loading the native library in a way that avoids these conflicts?

Any help or insight would be greatly appreciated. Thanks in advance!

本文标签: