I've build a native image with graalvm and micronaut, but my native-image app cannot get the environmental variable using @Value annotation. When I try to run the app as jar, it works just fine.
@Singleton
public class WebComponentService {
@Value("${config.adyen.merchantaccount}")
private String merchantAccount;
}
This is the error I get
Message: Error setting field value: No field 'merchantAccount' found for type: example.micronaut.getOriginKeys.WebComponentService Path Taken: new GetOriginKeysController([WebComponentService webComponentService]) io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for field [merchantAccount] of class: example.micronaut.getOriginKeys.WebComponentService
However, when I try to get the environmental variables like this, it works fine.
Map<String, String> environmentVars = System.getenv();
String merchantAccount = environmentVars.get("CONFIG_ADYEN_MERCHANTACCOUNT");
This is how I run the native app
$ CONFIG_ADYEN_MERCHANTACCOUNT=CommercetoolsGmbHDE775 ./theNativeApp
The key you have used here
@Value("${config.adyen.merchantaccount}")
is different thanenvironmentVars.get("CONFIG_ADYEN_MERCHANTACCOUNT");
Make sure they're the same