Spring Boot Native: Error withe the ' jasypt-spring-boot' module

366 Views Asked by At

I am trying to create a native executable from my Spring Boot 3.0.7 app (Java 17) using GraalVM. I am using GraalVM in a Docker build to create the native executable. I am using the "jasypt-spring-boot" (3.0.5) library to store the required app passwords in encrypted form.

The compilation of the app also seems to work from my point of view. However, the following error occurs when starting the app:


APPLICATION FAILED TO START


Description:

Failed to bind properties under 'bla.passwd' to java.lang.String:

Reason: org.jasypt.exceptions.EncryptionInitializationException: Cannot find a valid UNICODE normalizer: neither java.text.Normalizer nor com.ibm.icu.text.Normalizer have been found at the classpath. If you are using a version of the JDK older than JavaSE 6, you should include the icu4j library in your classpath.

The encrypted passwords contain only ASCII characters.

Update: I tried adding some reflection hints in my reflection-config.json, unfortunately without success:

  {
    "name": "com.ibm.icu.text.Normalizer",
    "allDeclaredConstructors": true,
    "allPublicConstructors": true,
    "allDeclaredMethods": true,
    "allPublicMethods": true,
    "allDeclaredFields": true,
    "allPublicFields": true,
    "allDeclaredClasses": true,
    "allPublicClasses": true
  },
  {
    "name": "java.text.Normalizer",
    "allDeclaredConstructors": true,
    "allPublicConstructors": true,
    "allDeclaredMethods": true,
    "allPublicMethods": true,
    "allDeclaredFields": true,
    "allPublicFields": true,
    "allDeclaredClasses": true,
    "allPublicClasses": true
  }

In my gradle script I have set the following configuration:

graalvmNative {
    binaries {
        all {
            resources.autodetect()
        }
        main {
            imageName.set('my-service')
            buildArgs.add('--verbose')
            buildArgs.add('-H:ReflectionConfigurationFiles=../../../src/main/resources/reflect-config.json')
        }
    }
}

I have added a small demo repository to demonstrate the issue: https://github.com/benocms/spring-native.test.git

Has anyone here had similar experiences and can possibly give me a hint?

Thank you very much.

1

There are 1 best solutions below

1
Andy Wilkinson On

Jasypt uses reflection to load the normalizer classes. It tries com.ibm.icu.text.Normalizer first and then, if that doesn't work, it tries java.text.Normalizer.

GraalVM can't tell that these classes are required so they aren't included in the native image and aren't, therefore, available to be loaded via reflection. You can correct this by providing some hints to GraalVM.